next up previous
Next: Variables Up: User-level Constructs Previous: Program Structure

Control Structure

Within the program's main routine and subroutines, the flow of execution is controlled using call, rcall, if, and for statements.



call, rcall

Call or reverse-call subroutine.
Syntax:

 (call  subname arg arg ...) or

(rcall subname arg arg ...)

Elements:
subname ---
The name of the subroutine to call. If zero or more than one subroutines with that name exist in the program, the result of the call is undefined.
arg, arg, ... ---
Actual arguments to the subroutine. These may be variables, constants, or expressions, with restrictions described below. The number of arguments must match the number of formal arguments listed in the subroutine's defsub statement.

Description:

A call or rcall statement is used to call a subroutine either forwards or in reverse, with arguments. If a particular actual argument is a variable or a memory reference, then the subroutine may actually change the value of its corresponding formal argument, and the caller will see the new value after the call is completed. If the argument is a constant or an expression, then it is an error for the subroutine to return with the corresponding formal argument having a value that is different from the value that the constant or expression evaluates to after the return. (Nonsensical behavior will result.)

Rcall differs from call only in that with rcall, the subroutine body is executed in the reverse direction from the direction in which the rcall is executed.



if

Conditional execution.
Syntax:

 (if ¯ condition then

statement

statement ...)

Elements:
condition ---
An expression representing a condition; considered ``true'' if its value is non-zero.
statement, statement, ... ---
Statements to execute if the condition is true.

Description:

An if statement conditionally executes the body statements if the condition expression evaluates to a non-zero value. If the value of the condition expression ever has a different value at the end of the body from the value it had at the beginning, then program behavior after that point will in general be nonsensical.

The top-level operation in the condition expression may be a normal expression operation, or one of the relational operators =, <, >, <=, >=, != which have the expected C-like meanings of signed integer comparison. These relational operators are not currently supported for use in expressions in contexts other than the top-level expressions in if conditions.

Actually the compiler does not yet moment support all the different relations with all of the possible types of arguments even in if conditions. The if implementation in the compiler needs some major rewriting.

In the future, if statements will also be allowed to appear in forms containing else clauses, using the syntax

 (if ¯ condition

if-statement if-statement ...

else

else-statement else-statement ... ) ,

but currently this form of if is not yet implemented by the compiler.



for

For loop; definite iteration.
Syntax:

 (for ¯ var =  start to  end

statement

statement ...)

Elements:
var ---
A variable name.
start ---
Start value expression.
end ---
End value expression.
statement, statement, ... ---
Statements to execute on each iteration.

Description:

A for statement performs definite iteration. Var must not exist as a variable at the point where the for construct appears, but it may exist as a name of a static data element, in which case this meaning will be shadowed during the for.

Before the loop, the start and end expressions are evaluated, and var is bound to the value of start. The scope of var is the body of the for. On each iteration, the body statements are executed. After each iteration, if var is equal to the value of end which was computed earlier, the loop terminates; otherwise, var is incremented as a mod- integer and the loop continues. After the loop, the start and end expressions are evaluated again in reverse to uncompute their stored values.

It is an error for either the start or end expressions to evaluate to different values after the loop than they do before the loop. If they do, program behavior afterwards will be nonsensical. The same goes for any of their subexpressions.

Note that although for is intended for definite iteration, in which the number of iterations is always exactly the difference between the initially-computed start and end values, actually there is nothing to prevent the value of var from being modified within the body, so that the number of iterations can actually be determined dynamically as the iteration proceeds. One can thus construct ``while''-like indefinite iteration functionality using for as a primitive. However, this is inconvenient, so the language will eventually explicitly include a while-like construct, though it does not do so currently.



next up previous
Next: Variables Up: User-level Constructs Previous: Program Structure



Michael Frank
Mon Nov 3 16:33:38 EST 1997