2.2 Modes, function classes

The symbols symbolic (or equivalent lisp) and algebraic play a double role: as a statement they switch the evaluation mode globally to symbolic or algebraic mode respectively, as a mode prefix they tell the REDUCE evaluator that one isolated evaluation should be done in the named mode. The scope of this prefix use can be rather narrow (e.g. one single expression) or cover a larger piece of code up to a complete procedure. Typically procedures in symbolic modules should be tagged “symbolic” explicitly although this might be redundant information in a totally symbolic context. If a procedure needs an evaluation mode different from the actual global one the mode prefix must be set.

In symbolic mode there are two additional procedure types available, macro and smacro. The discussion of macros is beyond the scope of this document - their use requires extensive knowledge of LISP. On the other hand smacros are frequently use in REDUCE and you will see lots of them in the sources. An smacro (an abbreviation for “substitution macro”) is an ordinary procedure tagged with the symbol “smacro” and usually with a rather small body. At source read time (or better: at REDUCE translator time) any call for an smacro will be replaced literally by the body of the smacro procedure which saves execution time for the call protocol at run time. So the purpose of smacros is twofold: encapsulation of frequently used pieces of code and an increased efficiency (avoiding function calls). Example:

     smacro procedure my_diff(x,y); x-y;  
 
     symbolic procedure hugo(a,b); my_diff(a,b);

Here the formal function call my_diff in the procedure literally is replaced by the body of the smacro where x and y are replaced by a and b. Obviously this translation can be done only if the smacro declaration is entered in a REDUCE session before the first reference. And later changes of an smacro don’t affect previously translated references.

Sometimes in older REDUCE sources you will find the symbol expr in front of a procedure declaration. This is more or less useless as the absence of macro or smacro symbols indicates that a procedure is of type expr - the default Standard LISP procedure type.