Description POP-2
1 description
1.1 stack
1.2 arrays , doublet functions
1.3 functions
1.4 operator definition
description
stack
pop-2 s syntax algol-like, except assignments other way round: instead of writing
a := 3;
one wrote
3 -> a;
the reason language had explicit notion of operand stack; thus, previous assignment written 2 separate statements:
3;
which evaluated value 3 , left on stack, and
-> a;
which popped top value off stack , assigned variable . similarly, function call
f(x, y, z);
could written as
x, y, z; f();
(commas , semicolons being largely interchangeable) or even
x, y, z.f;
or
(x, y, z).f;
because of stack-based paradigm, there no need distinguish between statements , expressions; thus, 2 constructs
if > b then
c -> e
else
d -> e
close;
and
if > b then
c
else
d
close -> e;
were equivalent (note use of close, endif hadn t been invented yet).
arrays , doublet functions
there no special language constructs creating arrays or record structures commonly understood: instead, these created aid of special builtin functions, e.g. newarray (for arrays contain type of item) , newanyarray creating restricted types of items.
thus, array element , record field accessors special cases of doublet function: function had function attached updater, called on receiving side of assignment. thus, if variable contained array, then
3 -> a(4);
was equivalent to
updater(a)(3, 4);
the builtin function updater returning updater of doublet. of course, updater doublet , used change updater component of doublet.
functions
variables hold values of type, including functions, first-class objects. thus, following constructs
function max x y; if x > y x else y close end;
and
vars max;
lambda x y; if x > y x else y close end -> max;
were equivalent.
an interesting operation on functions partial application, (sometimes referred currying ). in partial application number of rightmost arguments of function (which last ones placed on stack before function involved) frozen given values, produce new function of fewer arguments, closure of original function. instance, consider function computing general second-degree polynomials:
function poly2 x b c; * x * x + b * x + c end;
this bound, instance as
vars less1squared;
poly2(% 1, -2, 1%) -> less1squared;
such expression
less1squared(3)
applies closure of poly2 3 arguments frozen, argument 3, returning square of (3 - 1), 4. application of partially applied function causes frozen values (in case 1, -2, 1) added whatever on stack (in case 3), after original function poly2 invoked. uses top 4 items on stack, producing same result as
poly2(3, 1, -2, 1)
i.e.
1*3*3 + (-2)*3 + 1
operator definition
in pop-2, possible define new operations (operators in modern terms).
vars operation 3 +*;
lambda x y; x * x + y * y end -> nonop +*
the first line declares new operation +* precedence (priority) 3. second line creates function f(x,y)=x*x+y*y, , assigns newly declared operation +*.
Comments
Post a Comment