Usually, in a programming language, error conditions and boolean logic are unrelated topics.
In the offsider framework, however, they are related, as we shall show.
We deal with errors first.
You can generate an error by using the `Error' method. An example is
The generic form is
where arguments is optional, and depends on the errorKey. The arguments are inserted into the message designated for that errorKey, according to the message template for that errorKey.
The details of how this is implemented is not important here, what is important is what this method actually does.
The Error method does three things, and they all depend on the error key:
1. outputs a message to stderr
2. outputs an exit code to stdout
3. exits with the same exit code.
It has been designed this way to work well with the UNIX shell.
Typical usage, which you will see all through the framework source code is:
If the condition is false, then the method exits with a message AND an exit code.
will both yield TRUE for any value of KEY.
Also, even if you redirect the stderr, like so:
all of the above examples still work.
In summary, Dictionary Error will ALWAYS exit with an error, and write a non-zero integer to stdout. In addition, it will write a text message to stderr. (Actually, it returns an integer if the error template has been set up correctly. Currently, it is possible that it could return an arbitrary string if the programmer has been careless).
The Offsider framework is NOT a programming language, so it doesn't actually have any boolean logic built in. (It doesn't actually have a requirement for it).
Nevertheless, it has methods that act like boolean values when used from the UNIX shell.
For example, hasKey.
hasKey is used to determine whether a particular offsider has a particular key.
If true (the key exists), then it returns a non-empty string, and exits with a zero exit code.
If false (the key doesn't exist), then it returns nothing on stdout, and exits with a non-zero exit code.
Therefore, the following shell code will always work as expected:
The reason this works it that hasKey makes use of Error to generate appropriate error exit codes. This is just a convention, but the convention is used throughout the Offsider framework.
There is a convenience method called not. It basically changes an empty string to a non-empty string and vice-versa. It also adjusts the exit code appropriately.
The syntax is:
where message is any valid message.
The following two lines are equivalent in the UNIX shell:
If you have a multi-part message (a message within a message), then you can often place the not in various places within the message. You will need to think about how the message is parsed, and the meaning of the result. Remember, it is not really a boolean logic operator, it is a method that dispatches a message, and then manipulates the resulting string.
These both work as expected, and are equivalent:
This will not work as expected (ie, will work as expected, not.):
The reason this will not work is that the method hasKey doesn't parse for not. Ie, in this situation, not isn't even recognised as a method.
This will work, but what does it mean?
(answer, it is equivalent to saying either of the following:
(20100210 10:56:42) This page was produced using rsml. Source file was errorsAndLogic