Lately, while snooping around within old coding stuff, I rediscovered
an ancient treasure: the PostScript programming language.
It's older than dirt and situated deep down under the bottom of Adobe's PDF
technology. Intended to be an efficient and highly flexible printer
instruction language, it's actually a Turing-complete programming language,
based on a very clear and suprisingly simple stack-oriented concept,
outputting geometric results to suitable devices.
Everything is on a stack here.
That is, operators reduce items on the operand stack,
where operands are objects of various type.
Thus, calculations are denoted in reverse polish notation:
or, equivalently, and even more polish
where exch exchanges the two topmost operands.
PostScript procedures are executable arrays, i.e. objects consisting of a series of
operators and operands, enclosed in braces:
Executable objects may be executed at any time using the
exec operator.
Hence, functional concepts such as lambda expressions and lazy
evaluation immediately suggest themselves.
A complete script using certain font and graphic operators might look as follows:
Rendering is globally controlled by a transformation matrix, defining an
affine transformation (i.e. a linear mapping plus translation) that can be
modified either by the translate, scale, and
rotate operators or by
explicit left-sided matrix multiplication using the concat operator.
A named procedure in the usual manner is obtained as an executable literal
that can be stored within the current dictionary.
That is, the def operator is used to manage the symbol table:
Now, as an apprentice piece of recursive geometry, let's see how
Koch's famous Snowflake works:
The koch function reduces a step and a length parameter
from the stack, while depth is defined in the global dictionary.
The decision of whether dive into recursion incrementing the step value
or stop and draw a line segment is made by help of the ifelse operator.
So,
displays the curve of length 100 with a recursion depth of 5.
Zora commented on 2010-09-20T23:46:38+00:00
*impressed*
by Zora
→ reply to comment