Local Variables (Continuation)

Now we can return to the topic of local variables.

Namely, local variables can be bound to values by means of a path of the form
    S :: He R
where S is a source, R is a rest, and He is a so called "hard expression". The hard expression He, which consists of symbols, brackets, and variables, must satisfy the following restrictions:

It can be easily seen that, being a hard expression, He can be regarded as a format expression, and the Refal Plus compiler verifies that S is certain to return ground expressions satisfying the format He.

The path S :: He R is evaluated as follows. First, the source S is evaluated. If the result returned is a ground expression Ge, the variables in He are bound to the corresponding subexpressions of Ge. Then the rest R is evaluated, and the result returned is taken to be the result of the whole construct.

It should be noted that the evaluation of the path S :: He R begins by evaluating the source S in the environment in which the whole construct is evaluated. Then the variables in He are bound, and the environment is extended with the new bindings, so that the rest R is evaluated in the extended environment. Thus the evaluation of the path
    100 :: sX, <Add sX 1> :: sX = sX
returns 101.

The hard expression He in a path S :: He R may be empty, in which case the path takes the form S :: R and can be abbreviated to S R.

This construct (called condition) is usually used in cases where we are interested in the side effects produced by evaluating S, rather than in the result returned by S.

For example, evaluating the path
    <PrintLn "A">, <PrintLn "B">, <PrintLn "C"> =
causes three lines to be printed, the first line consisting of the character A, the second of the character B, and the third of the character C.

The rest R in a path S :: He R may consist of a single comma, in which case the path takes the form S :: He , and can be abbreviated to S :: He .