Formats of Functions

From the purely formal point of view, all Refal Plus functions are assumed to take a single argument and to return a single result. In many cases, however, the structure of a function's argument and result is known in advance. For example, the function Add is known to accept a ground expression consisting of two symbols and to return a ground expression consisting of a single symbol.

The restrictions imposed on the argument and result of a function are specified by the declaration of the function. For example, the declaration of the function Add has the form:
    $func Add sX sY = sZ;
In general, the declaration of a function Fname has the form
    $func Fname Fin = Fout;

where Fin is the input format of the function, and Fout is its output format. The formats of functions may contain symbols, parentheses, and variables. The variable indices in formats are insignificant, serve as comments, and may be omitted.

All input and output formats must be "hard", which means that any subexpression of a format may contain no more that one ve-variable at the top level of parentheses. For example, the format (e)(e) is hard, whereas the format e A e is not hard, containing as it does two e-variables at the same level of parentheses.

All inputs to, and results of, a function must have the structure specified by the function's declaration. The function's declaration must precede all references to the function made in the result expressions appearing in the program. If the function is defined in the program, its declaration must explicitly appear in the program prior to the definition. Otherwise, if the function is defined in other module, its declaration must be imported into the program by a directive $use.

When the program is being compiled, the compiler verifies that the argument expressions in the calls to the function are consistent with the input format of the function. For example, consider the result expression
    <Add 2 <Add sX sY>> 
The inner call is obviously correct. But, to check the outer call, we have to make use of the information about the structure of the results returned by the function Add. Thus, on replacing <Add sX sY> with the output format of the function Add we get <Add 2 s> . Now we see that the argument of the outer call conforms to the input format of the function Add. On the other hand, the result expression
     <Add 2 <Add sX sY> 3> 

is regarded as illegal, because the argument of the outer call consists of three symbols, despite the input format of the function Add requiring the argument to consist of two symbols.

Thus, specifying the input and output formats enables many errors to be found at compile time, rather than at run time.

From the purely formal point of view, all Refal Plus functions are assumed to take a single argument and to return a single result. In many cases, however, the structure of a function's argument and result is known in advance. For example, the function Add is known to accept a ground expression consisting of two symbols and to return a ground expression consisting of a single symbol.

The restrictions imposed on the argument and result of a function are specified by the declaration of the function. For example, the declaration of the function Add has the form:
    $func Add sX sY = sZ;
In general, the declaration of a function Fname has the form
    $func Fname Fin = Fout;

where Fin is the input format of the function, and Fout is its output format. The formats of functions may contain symbols, parentheses, and variables. The variable indices in formats are insignificant, serve as comments, and may be omitted.

All input and output formats must be "hard", which means that any subexpression of a format may contain no more that one ve-variable at the top level of parentheses. For example, the format (e)(e) is hard, whereas the format e A e is not hard, containing as it does two e-variables at the same level of parentheses.

All inputs to, and results of, a function must have the structure specified by the function's declaration. The function's declaration must precede all references to the function made in the result expressions appearing in the program. If the function is defined in the program, its declaration must explicitly appear in the program prior to the definition. Otherwise, if the function is defined in other module, its declaration must be imported into the program by a directive $use.

When the program is being compiled, the compiler verifies that the argument expressions in the calls to the function are consistent with the input format of the function. For example, consider the result expression
     <Add 2 <Add sX sY>> 
The inner call is obviously correct. But, to check the outer call, we have to make use of the information about the structure of the results returned by the function Add. Thus, on replacing <Add sX sY> with the output format of the function Add we get <Add 2 s> . Now we see that the argument of the outer call conforms to the input format of the function Add. On the other hand, the result expression
     <Add 2 <Add sX sY> 3> 

is regarded as illegal, because the argument of the outer call consists of three symbols, despite the input format of the function Add requiring the argument to consist of two symbols.

Thus, specifying the input and output formats enables many errors to be found at compile time, rather than at run time.