When we enter refgo or reftr command, we start a program which is an efficient interpreter of Refal. The fact that it is an interpreter means that the computer will basically imitate the steps of the Refal machine. It will maintain two storages: the program field and the view field; these will be representations of the program field and the view field of the abstract Refal machine.
At each step the computer will find the primary active sub-expression in the view field and apply one of the sentences in the program field to it. This will result in the replacement of the active sub-expression by another sub-expression. By calling the interpeter efficient we mean that it will use certain addresses in memory to jump directly to the needed points in memory without passing through intervening expressions, as the definition of the abstract Refal machine suggests. It must also avoid unnecessary copying of expressions. More specifically, the following requirements must be met:
The user of Refal need not know anything about the actual representation of expressions, aside from the fact that these five requirements are satisfied. The obvious way to satisfy them is to use doubly linked lists, with brackets keeping the reference to the pair bracket, in addition to forward and backward references. This is what we actually do in the Refal system. In order to jump to the next active sub-expression, we keep a stack of the addresses of active sub-expressions (stack of function calls). The Refal compiler, called as refc , translates the Refal program into an intermediate language RASL and creates a file which consists of subfields, each of which keeps one function definition. These subfields are accessed at run time through a hash table.
List elements representing Refal symbols include codes of the symbol's type. In this way the system distinguishes between characters, identifiers, macrodigits and real numbers. To convert one type into another (e.g., the digit string '321' into the macrodigit 321 or the identifier Sum into the string 'SUM' etc.) use the corresponding built-in functions described in Reference Section C.
If this
brief description of the inside of the Refal system
does not tell you much, do not worry: once again,
you do not really need to know it if you only want to use the language.
Exercise 2.4
Define a function <Merge s.1 s.2>
which creates a
new identifier by concatenating the "bodies"
(string representations)
of the identifiers s.1
and s.2
.