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.
$func Add sX sY = sZ;
$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.
<Add 2 <Add sX sY>>
<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.
$func Add sX sY = sZ;
$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.
<Add 2 <Add sX sY>>
<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.