Functions which have once been defined need not be defined again. Neither need they be compiled again. While function definitions in Refal are stored in files with the extension .ref , their translations into the intermediate language RASL are stored in the corresponding files with the extension rsl . When we write a big program we often break it into a number of parts called modules, test and debug them separately, and then combine them into a whole program.
Some functions in a module are going to be called by functions from other modules. Other functions are auxiliary; the user need not know about their existence at all. This might create a conflict of names. Indeed, suppose that two programmers each wrote their module and used the same name for one of their auxiliary functions. How then will the Refal machine know which of the definitions to use?
This problem is solved by designating some functions in each module as entry functions. Only entry functions can be called from other modules. To define a function as entry, simply add the keyword $ENTRY in front of the function name that opens the definition. Let an entry function F1 be defined in a module Mod1 :
* Module Mod1 $ENTRY F1 { ... }
In order to call F1 from another module Mod2 , this function must be declared in Mod2 as an external function:
* Module Mod2 $EXTRN F1; ... <F1 ...> ...
The external statement indicates to the compiler that F1 is defined as an entry point in some other module, not in the current one. That module (Mod1 in our example) must be included in the call of refgo or reftr :
refgo Mod2+Mod1
More than one function may be declared as external in one external statement:
$EXTRN F1,F2,F3;
The names of entry functions must be unique for all modules that are used together. Functions that are not declared as entry can be called only from a function defined in the same module. In this way, naming conflicts are resolved. When writing a module you can invent any names for auxiliary functions, without worrying about function names in other modules.
Among the modules used together, one must include the definition of the starting function Go ; it will be referred to as the main module. If, in addition to the main module Mainmod , you want to use some modules Mod1 , Mod2 , etc. to Modn , enter:
refgo Mainmod+Mod1+Mod2+ ... +Modnor:
reftr Mainmod+Mod1+Mod2+ ... +Modn
Take this typical situation. The function Go , which does the job, is defined in the module prog1 and some of the functions needed are defined in a module called functions . You also need a number of regularly used functions which you gathered in the module reflib . If all three modules are already available in the RASL form then to run prog1 you enter:
refgo prog1+functions+reflib
Besides the main module other modules may also include a definition of the function Go . It will be ignored as long as the module does not take the first place in the list.