Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Working with Links

We have already seen examples of how links can be used in conjunction with Irnix. Now we will examine the topic of link usage more thoroughly and deeply.

Links help reuse code, as well as rename entities.

For instance, we might imagine that we have some library of Irnix objects, which is simply a regular directory ~/library containing scripts and contracts. Suppose it looks roughly like this:

~/library
├── method1
├── method2
├── method3
├── ...
└── methodn

We can create a link to this directory in a namespace, and we may name it whatever we wish, thereby selecting the name for our object:

ln -s ~/library object
~/.local/share/irnix
└── object -> ~/library

Afterwards we can use methods from the ~/library directory:

irnix e object.method2 -- 'Hello World!'

Thus code can be reused efficiently. Here is another example: we can copy a method body by creating links:

ln method method2
ln -s method method3
~/.local/share/irnix
└── object
    ├── method
    ├── method2 -> method
    └── method3 -> method

Such methods can be used like ordinary ones, and Irnix will invoke the same file method:

irnix e object.method
irnix e object.method2
irnix e object.method3

In the chapter Strict Classification we covered which entities are not considered objects or methods. Now we’ll look at a number of examples that explicitly turn them into methods and objects.

Take as an example some file script.sh located inside the object object:

~/.local/share/irnix
└── object
    └── script.sh

Such a script cannot be called directly, because script.sh is not considered a method. But we can explicitly make it a method that points to script.sh:

cd ~/.local/share/irnix/object
ln -s script.sh method
~/.local/share/irnix
└── object
	├── method -> script.sh
    └── script.sh

Afterwards a contract can be written for such a method and it can be called, provided that the file script.sh itself has execute permission:

irnix e object.method

Take as a second example the standard namespace ~/.local/share/irnix and turn it into an object by creating a link:

ln -s . self
~/.local/share/irnix
└── self -> .

Now self mimics an object, because it is a directory and does not contain dots in its name. If we add a method method, it can be invoked:

irnix e self.method
~/.local/share/irnix
├── method
└── self -> .

Thus we turn the namespace into an object self and do not leave the method method orphaned without an object. If you try to call just the method (irnix e method), Irnix will output an error message.