Up | Next | Tail |
In a PSL program the flow of control is described primarily by function application. A function may call any number of other functions, including itself. This allows complex operations to be described by a number of small functions, each of which implements a simple operation. In addition, PSL provides a number of other control constructs.
A typical application of cond is shown below, the square brackets are used to indicate zero of
more occurances of an expression.
The first form in each clause is treated as a predicate; the remaining (zero or more) forms are
treated as if they were enclosed within a progn. The evaluation proceeds by sequentially
evaluating the predicates in the order of their appearance until one evaluates to a non-nil value.
Then the remaining forms in this clause are evaluated and the value of the last form is returned
as the result. If only the predicate appears, then its value (if non-nil) becomes the value returned.
If no predicate is non-nil then the result is nil. The following definition demonstrates the use of
cond.
This function will compute the length of lists strings and vectors.
The following macros are defined in the USEFUL module.
The expression
is preferred over
Notice that a single form is evaluated when the test expression E is non-nil but there may be any number of expressions evaluated when the value of E is nil.
Related macros for common cond forms are when and unless.
which relies upon the order of the evaluation of the arguments is often used. If and had evaluated the second argument first an error may have been generated. However, the arguments are always evaluated from left to right. Or may be used to retrieve a value as in the function definition below.
In this example the function which is applied is either found on the property list of the data or it is a default. In reading such an expression one considers an argument to be preferred over anything which follows it. Note that the use of these functions as conditionals may yield code which is confusing. For example the code
will set x to 3 if y is bound to a value other than nil, otherwise x will be set to nil. It is recommended that the following be used instead.
The following version of if is defined in the module if. It is upward compatible with the if macro defined above. This version will accept the keywords then, else, and elseif. If a keyword appears immediately after the conditional expression of the if then the expression is taken to be in keyword form.
This is not the same notation used generally in the PSL manual. Square brackets enclose parts optionally present. The ellipses indicate arbitrary additional repetitions of the thing appearing just before them. The elseif-part may be one of two forms.Up | Next | Front |