A Syntax-Related Subtlety: Paths, Rests, and Sources

Now we have to put aside the topic of "local variables" and consider some subtle points concerning the syntax of Refal Plus. These points are not related to the essence of Refal Plus, but rather are due to the fact that the authors of Refal Plus tried to make the syntas of Refal Plus as terse as possible. Unfortunately, this resulted in certain complications in the syntax of Refal Plus.

Basically, all Refal Plus constructs appearing in function definitions are meant either for analyzing the structure of ground expressions or for computing some results. While the analysis of data is performed by means of patterns, the constructs that are used for producing results are paths.

The term path was chosen in order to emphasize that producing a result is a sophisticated process, which can involve a sequence of steps. In a sense, the evaluation moves forward step-by-step "along a path".

A result expression is a "degenerate" kind of path, whose evaluation can be done in a single step.

The construct
    = <Sub sX 1> :: sY,
      <Mult sY sY>;
is a more sophisticated example of a path. In this case the evaluation takes 2 steps. The first step produces an intermediate result, which is used at the second step, in the evaluation of the result expression <Mult sY sY>.
It should be noted that the comma , is a purely sintactic device, denoting as it does no real action. However, should we try to remove it
    = <Sub sX 1> :: sY
      <Mult sY sY>;
an ambiguity would arise: it would be unclear, how to divide the path into the binding and the result expression?

For the purpose of avoiding ambiguity, the description of Refal Plus distinguishes two special classes of paths: rests and sources. Rests and sources are "well-behaved" paths that possess some useful sintactic properties.

A rest is a path that starts with a keyword, which enables it to be unambiguously separated from the preceeding construct. It should be noted that Refal Plus "keywords" are not necessary "words" consisting of letters, but may also be combinations of other characters. For example
    = A B C
    , A B C
are sampes of rests. (There is a subtle difference between = and , , but it shows up only when the evaluation produces a "failure". So, at the moment, this difference is not essential.)
A source is a path that contain no commas at the top level of curly braces. For example
    A B C
    \{ <Sub sX 1> :: sY, <Mult sY sY>; }
are samples of sources. The term source is used because, when used in bindings, sources produce values for varibles.

In the following, in the description of Refal Plus, paths will be denoted by Q, rests by R, and sources by S.

If a path Q is not a rest, it can always be turned into a rest, without changing its meaning, by prefixing it with a comma: , Q .

If a path Q is not a source, it can always be turned into a source, without changing its meaning, by enclosing it in curly braces \{ Q; } .