Result Expressions

Refal Plus result expressions are, in a sense, an analog to the well-known arithmetic expressions. They may contain constants, variables and function calls, and are used for producing new ground expressions from constants and variable values.

For example, the arithmetic expression X*Y+3 corresponds to the Refal Plus result expression
    <Add <Mult sX sY> 3>
Each pair of angular brackets designates a function call of the form <Fname Re>, where Fname is the name of the function to be called, and Re is the argument to be passed to the function. Thus, the arguments of function calls are always enclosed in angular "functional" brackets, which eliminates the necessity to use parentheses for indicating the order in which the subexpressions are to be evaluated. For example, the expression X*(A+B) rewritten in Refal becomes
    <Mult sX <Add sA sB>> 
whereas the expression X*A+B is written in Refal as
    <Add <Mult sX sA> sB> 

Result expressions, similarly to arithmetic expressions in other languages, are used for producing new values from other ones. Thus, a result expression is evaluated by replacing all its variables with their values and evaluating all function calls. If there are nested function calls, the inner calls are evaluated before the surrounding ones.

It is obvious that, for a result expression to be evaluated, it is necessary to know the values of the variables appearing in the expression. The information about the variable values will be referred to as an environment. The notation
    {V1 = Ge1, ..., Vn = Gen}
will be used for denoting the environment in which the variables V1, ..., Vn have the respective values Ge1, ..., Gen.

As can be seen from the above, the representation of arithmetic expressions by result expressions is rather clumsy. Nevertheless, it does have certain advantages.

The point is that the choice of one or another notation is determined by the nature of the objects to be dealt with, as well as by the set of operations to be applied to the objects.

It is reasonable to choose the notation in such a way that the most frequently used operations be denoted as concisely as possible. But the most succinct notation is, certainly, no notation at all, i.e. an empty place!

As far as arithmetic expressions are concerned, we have two basic operations: addition and multiplication. One of the operations may be denoted by empty place, and the common practice is to omit the operator of multiplication.

On the other hand, the principal data dealt with by Refal Plus are ground expressions, rather than numbers. Since the basic operations on ground expression are the concatenation of two expressions and the enclosing of an expression in parentheses, it is for these operations that the syntax of Refal Plus provides a very concise notation.

Namely, if Re' and Re'' are result expressions, so is the construct
    Re' Re"
which means that Re' and Re'' are to be evaluated and the values returned are to be concatenated to produce the result of the whole expression. Thus, if the evaluation of Re' and Re'' results in returning ground expressions Ge' and Ge'' respectively, the ground expression Ge' Ge'' is returned as the result of evaluating Re' Re".
If Re is a result expression, so is the construct
    ( Re )
which means that Re is to be evaluated and the value returned is to be enclosed in parentheses to produce the result of the whole expression. Thus, if the evaluation of Re results in returning a ground expression Ge, the ground expression ( Ge ) is returned as the result of evaluating ( Re ) .
For example, the result of evaluating the result expression
    sX '+' sY (eZ)
in the environment {sX = 25, sY = 36, eZ = A (B C) D} is the ground expression
    25 '+' 36 (A (B C) D)