next up previous contents
Next: the NeXTSTEP operating system Up: Introduction Previous: the theory of complex

the programming language REC

The programming language REC was derived from LISP over a period of time, and found to be useful for minicomputers such as Digital Equipment's PDP-8, or early microprocessors such as the IMSAI or Polymorphic 88, given its extreme conciseness. That, in fact, is the reason why it is still preserved as an interface to programs written in other languages running with other operating systems.

REC itself is strictly a control structure, using parentheses to group sequences of instructions which are supposed to be executed in order -- in other words, programs. The instructions themselves, which are subdivided into operators and predicates, are not part of the control structure, but are always defined separately to create specialized variants on REC.

Besides the use of parentheses for aggrupation, the two punctuation marks, colon and semicolon, are used for repetition and termination, respectively; they were somewhat borrowed from musical notation. Spaces, tabs, all the C ``white space,'' are used for cosmetic purposes and must be ignored.

There is also a mechanism for defining subroutines; definitions and their associated symbols alternate between a balanced pair of curly brackets, terminating in a main program which remains nameless. Definitions so introduced are valid only within their braces, permitting symbols to be reused over and over again on different levels and in different places. A subroutine is actually executed by prefacing its name with an ``at sign,'' as in @x.

The distinction between operators and predicates is somewhat artificial, made mostly for convenience; a predicate which is always true is an operator. The values true and false of a predicate govern the sequence of operations, true meaning that the text of the program continues to be read in order, consecutively from left to right.

But false makes use of the punctuation, implying a skip to the next colon, semicolon, (or right parenthesis, in their absence) at the same parenthesis level. A colon means repetition starting back at the left parenthesis, a semicolon gives a true termination, realized by going forward to the closing right parenthesis, Arriving at a right parenthesis without the benefit of punctuation gives a false termination, but more generally inverts the action of predicates enclosed in such an interval.

This convention allows negating a predicate: (p) behaves oppositely from p. The other boolean combinations of predicates are easily written; ``p and q'' translates into (pq;), ``p or q'' into (p;q;). Moreover, all programs are predicates, even the main program, thereby reporting their results to the next higher program level, the one in which they occur as a subroutine.

REC/C uses about forty operators, of which only the counter !n! and some comparisons are predicates. They are more easily remembered if they are broken down into specific classes, such as the arithmatical operations, or the evaluation of some predefined functions. The central operating element of REC/C is a pushdown list onto which complex constants will be gathered, later to be evaluated, consulted, or replaced by the results of diverse calculations. The flow of data in and around the stack is shown in figure 7.

binary arithmetic operations
:
+
- add top two numbers, leave only their sum
-
- subtract top two numbers, leave their difference
*
- multiply top two numbers, leave their product
/
- divide top two numbers, leave their quotient
&
- exchange top two items on stack leaving both
unary arithmetic operations on top of stack
:
j
- complex conjugate
n
- negative
f
- multiply by real factor, as in $xx.x$ f
library of common functions
:
C
- hyperbolic cosine
E
- complex exponential
F
- fractional linear mapping (z+1)/(z-1)
L
- complex logarithm
r
- complex square root
T
- hyperbolic tangent
push constants onto the stack
:
X
- push 1
Y
- push i
Z
- push 0
u
- push 0.1
v
- push 0.1 i
x
- push 0.01
y
- push 0.01 i
graphical display from the top of the stack
:
G
- move to first point of a drawn line
g
- continue line to additional points
Q
- draw a colored square (one argument)
q
- draw a small colored square (2 args)
s
- draw a small stereo square (2 args)
z
- draw a small circle (one argument)
save and restore constants, adjust top of stack
:
R
- Rn to recover nth constant by pushing it
S
- Sn to save nth constant leaving stack intact
P
- push by duplicating the top of the stack
p
- pop the stack by discarding its top element
REC background
:
!n!
- (!n! ... :;) repeat ... n times
$xx.x$
- floating point number
set parameter values
:
M
- graphic multiplier: $10.0$ M, default
m
- square size: $1.25$ m, default
c
- compression threshold (nominal 0.15)
predicates
:
A
- Is angle a multiple of 90 degrees?
I
- Is real part an integer?
i
- Is real part a multiple of 0.1?
lx
- supervise recursive depth

There are several documents available explaining REC [1], including a read.me file in the rec subproject of each of the REC files.


next up previous contents
Next: the NeXTSTEP operating system Up: Introduction Previous: the theory of complex
Microcomputadoras
2001-02-12