next up previous
Next: The NeXTSTEP operating system Up: Introduction Previous: The theory of flexagons

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.

Having a specialized REC for flexagon design requires programming the operations used in the process, which includes generating the base polygon and then drawing a succession of reflections in prescribed sides. Although flexagons can be elaborated recursively to any degree, it is rare that as many as three levels would be used before the physical structure becomes impossible to manipulate. Consequently no terminating predicate has been included; just a specified finite polygon strip will be drawn.

REC-F uses the following ten operators; only the counter !n! is a predicate.

Xk - create a k-gon

C - draw the polygon

o - offset the polygon

n - reflect in the previous edge

N - reflect in the next edge

Rk - reflect in edge k

O - read a polygon off the stack

P - push the polygon onto the stack

p - pop the polygon from the stack

!n! - (!n! ... :;) repeat ... n times

For example, (X5 C;) would create and display a regular pentagon.

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

next up previous
Next: The NeXTSTEP operating system Up: Introduction Previous: The theory of flexagons