Previous page Table of Contents Next page
The language semantics require tail recursion removal, so iteration can be accomplished simply by writing a recursive function. However, for readability several iteration statements are defined by macros. These do not have to be part of the PLOT language per se, they are a library that could have been written by a user. However it is likely that most programs use that library.
defmacro while ?test ?:body => ... defmacro until ?test ?:body => ...
These repeatedly execute the body zero or more times until the test is false or true, respectively. The scope of any definition in the test includes the body. The entire statement is enclosed in a block. The result is always false.
defmacro for { ?:for-clause & , ^^ }+ ?:body => ...
A for statement begins with one or more clauses, separated by commas. The remainder of the statement is the body. The entire statement is enclosed in a block. (There is not actually a syntactic type named for-clause.)
Each clause can be an iteration clause or an endtest clause. An endtest clause specifies a test that controls whether the iteration repeats. An iteration clause specifies a variable and a set of values that it will assume in successive iterations. All iteration variables take on their values in parallel. An iteration clause can also imply an endtest.
The body is in the scope of additional "result" statements, defined by local macro definitions, that allow control over the value of the for statement. The default value is false if these are not used.
The full details of the for statement are in the next section.
Example:
for x in sequence, i from 0, while test?(x) if test2?(i) collect x
Previous page Table of Contents Next page