There are two different forms of looping in Wrapl.
The simplest way to write a loop in Wrapl is with the expression REP body, which simply keeps evaluating body.
By itself, a REP expression is not much use. However, the body of a loop may be a block which may contain exit expressions EXIT value which cause the loop to terminate producing the values of value. For example:
The value after EXIT is optional; if no value is provided, then the loop produces NIL. The two expressions WHILE condition and UNTIL condition are syntax sugar for condition // EXIT NIL and condition => EXIT NIL respectively. Thus a loop like:
in C would look like
in Wrapl. A loop like:
would be equivalent to
You can have any number of EXIT expressions (and hence WHILE and UNTIL expressions) in a loop. The step expression STEP causes the loop to start the next iteration immediately.
Since expressions in Wrapl can produce more than value, they can be used for looping using an EVERY expression. The expression EVERY condition DO body evaluates body once for each value produced by condition. Since an EVERY expression normally terminates when condition fails to produce any more values, usually the entire EVERY expression fails to produce any value.
Both STEP and EXIT expressions (and hence WHILE and UNTIL expressions) can be used within condition and body, allowing EVERY expressions to produce values. The DO body clause can be omitted, which is equivalent to using DO NIL.
Variables are one example of references, i.e. they both have a value and can be assigned a new value. Wrapl allows references to be passed to and returned from functions. Arguments which evaluate to references are passed as such to functions, however when the function is called, it normally only uses the current values of those arguments. Declaring a parameter with a proceeding + indicates that the parameter should use the reference to the argument, so that assigning a value to the parameter within the function changes the value of the argument itself.
Similarly, references are returned from functions as such, and can be assigned to like a variable.
The result of any expression can be a reference.