POP-2 |
POP-2 was a . Its syntax was Algol-like, except that assignments were backwards: instead of writing
a := 3;
one wrote
3 -> a;
The reason for this was that the language had explicit notion of an Stack (computing) ; thus, the previous assignment could be written as two separate statements:
3;
which evaluated the value 3 and left it on the stack, and
->a;
which popped the top value off the stack and assigned it to the variable a . Similarly, the function call
f(x, y, z);
could be written as
x, y, z; f();
(commas and semicolons being largely interchangeable) or even
x, y, z.f;
or
(x, y, z).f;
There were no special language constructs for creating arrays or record structures as they are commonly understood: instead, these were created with the aid of special builtin functions. Thus, array element and record field accessors were simply special cases of a doublet function : this was a function that had another function attached as its updater , which was called on the receiving side of an assignment. Thus, if the variable a contained an array, then
3 -> a(4);
was equivalent to
updater(a)(3, 4);
the builtin function updater returning the updater of the doublet. Of course, updater was itself a doublet and could be used to change the updater component of a doublet.
Because of the stack-based paradigm, there was no need to distinguish between statements and expressions ; thus, the two constructs
if a > b then c -> e else d -> e close;
and
if a > b then c else d close -> e;
were equivalent (note the use of close as endif hadn t been invented yet).
Variables could hold values of any type, including functions, which were first-class objects. Thus, the following constructs
function max x y; if x > y then x else y close end;
and
vars max; lambda x y; if x > y then x else y close end -> max;
were equivalent. An interesting operation on functions was partial application ; this was where some number of the rightmost arguments of the function were frozen to given values, to produce a new function of fewer arguments. For instance, consider a function for computing general second-degree polynomials:
function poly2 x a b c; a * x * x + b * x + c end;
This could be bound, for instance as
vars less1squared; poly2(% 1, -2, 1 %) -> less1squared;
such that the expression
less1squared(3)
returns the square of (3 - 1), which is 4.
POP-11 was a later development of POP-2.
=See also=
=External links=
|
|