Go to the first, previous, next, last section, table of contents.


Special Forms

Special forms, although syntactically equivalent to macros, differ from macros in that their arguments are not automatically evaluated before they are called. The evaluation of their arguments usually depend on some condition of some other argument.

Special Form: if (condition,consequent[,alternative])
Evaluates condition and, if its boolean value is TRUE, evaluates consequent. Otherwise, alternative is evaluated, if specified.

Special Form: cond ([condition,consequent[,...]])
Evaluates the conditions one at a time and checks for their boolean value. If a condition with a value of TRUE is encountered, its corresponding consequent is evaluated and its result returned. If no condition evaluates to TRUE, nothing is done. Example:

%<number=23>\
%cond(%[number < 10],less than 10,
      %[number < 50],less than 50 but greater than 9,
      else,greater than 49)
=> less than 50 but greater than 9

Special Form: case (string,list,consequent[,...[,else,alternative]])
Evaluates string to a scalar. Then, one at a time evaluates each list and checks whether string is contained in the resulting list. If it is, the corresponding consequent is evaluated and its result returned. If the else clause is specified and the string is contained in no list, its alternative is evaluated. Otherwise, nothing is done. Example:

%<number=7>\
%case(%number,
      %list(0,2,4,6,8),even,
      %list(1,3,5,7,9),odd)
=> odd

Special Form: for (counter,start,stop,[increment,]body)
Evaluates counter, start, stop and, if specified, increment. The values of start, stop and increment must be integer numbers. If increment is not specified, an increment of @math{1} is used if start is greater than stop, otherwise @math{-1}. Then counts, beginning with start, while the value of the counter is before or equal to stop in the counting direction. For each step, evaluates body in a new environment where counter is bound to the value of the counter.

A few examples:

%for(i,1,10,%i%' ')
=> 1 2 3 4 5 6 7 8 9 10
%for(i,10,1,%i%' ')
=> 10 9 8 7 6 5 4 3 2 1
%for(i,1,10,2,%i%' ')
=> 1 3 5 7 9
%for(i,10,1,-2,%i%' ')
=> 10 8 6 4 2
%for(i,1,10,0,%i%' ')
error--> increment in for-loop cannot be zero
%for(i,10,1,1,%i%' ')
=>

Special Form: foreach (counter,list,body)
Evaluates counter and list, which must yield a list. Then iterates over this list evaluating body in a new environment in which counter is bound to the current list element.

Special Form: foreachkey (counter,hash,body)
Evaluates counter and hash, which must yield a hash. Then iterates over all keys in the hash evaluating body in a new environment in which counter is bound to the current hash key.

Special Form: while (condition,expr)
Evaluates condition. If this yields a boolean value of TRUE, expr is evaluated, otherwise the loop is finished. Then repeats the cycle.

Special Form: until (condition,expr)
Evaluates condition. If this yields a boolean value of TRUE, the loop is finished, otherwise expr is evaluated. Then repeats the cycle.

Special Form: dowhile (expr,condition)
Evaluates expr, then evaluates condition. If this yields a boolean value of TRUE, the cycle is repeated.

Special Form: dountil (expr,condition)
Evaluates expr, then evaluates condition. If this yields a boolean value of TRUE, the loop is finished, otherwise the cycle is repeated.

Special Form: and ([expr[,...]])
Evaluates the exprs from left to right. For the first expr evaluating to boolean FALSE, returns 0. If all exprs evaluate to boolean TRUE, returns 1. This means that if one expr evaluates to FALSE, all exprs to its right do not get evaluated. If and is called without parameters, it returns 1.

Special Form: or ([expr[,...]])
Evaluates the exprs from left to right. For the first expr evaluating to boolean TRUE, returns 1. If all exprs evaluate to boolean FALSE, returns 0. This means that if one expr evaluates to TRUE, all exprs to its right do not get evaluated. If or is called without parameters, it returns 0.

Special Form: define (name,argname[,argname...],body)
Defines a macro with the name name and the specified argument names. The body body is not evaluated.

Special Form: locals (symbol[,symbol...],body)
Evaluates body in a new scope with the specified local variables.


Go to the first, previous, next, last section, table of contents.