POP-2


POP-2 is a programming language developed around 1970 from the earlier language POP-1 by Robin Popplestone and Rod Burstall at the University of Edinburgh. It drew roots from many sources: the languages LISP and ALGOL 60, and theoretical ideas from Peter J. Landin. It used an incremental compiler, which gave it some of the flexibility of an interpreted language, including allowing new function definitions at run time and modification of function definitions while a program was running, without the overhead of an interpreted language.

Description

Stack

POP-2's syntax was Algol-like, except that assignments were the other way round: instead of writing
a := 3;
one wrote
3 -> a;
The reason for this was that the language had explicit notion of an operand stack; 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;
could be written as
x, y, z; f;
or even
x, y, z.f;
or
.f;
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.

Arrays and doublet functions

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, e.g. and for creating restricted types of items.
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 , which was called on the receiving side of an assignment. Thus, if the variable a contained an array, then
3 -> a;
was equivalent to
updater;
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.

Functions

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 ,. In partial application some number of the rightmost arguments of the function were frozen to given values, to produce a new function of fewer arguments, which is a closure of the original function. 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 -> less1squared;
such that the expression
less1squared
applies the closure of poly2 with three arguments frozen, to the argument 3, returning the square of, which is 4. The application of the partially applied function causes the frozen values to be added to whatever is already on the stack, after which the original function poly2 is invoked. It then uses the top four items on the stack, producing the same result as
poly2
i.e.
1*3*3 + *3 + 1

Operator definition

In POP-2, it was possible to define new operations.
vars operation 3 +*;
lambda x y; x * x + y * y end -> nonop +*
The first line declares a new operation +* with precedence 3. The second line creates a function f=x*x+y*y, and assigns it to the newly declared operation +*.

History

The original version of POP-2 was implemented on an Elliott 4130 computer in the University of Edinburgh.
In the mid-1970s, POP-2 was ported to BESM-6.
Later versions were implemented for CTL Modular One, PDP-10, ICL 1900 series. Julian Davies, in Edinburgh, implemented an extended version of POP-2, which he called POP-10 on the PDP-10 computer running TOPS-10. This was the first dialect of POP-2 that treated case as significant in identifier names, used lower case for most system identifiers, and supported long identifiers with more than 8 characters.
Shortly after that, a new implementation known as WPOP was implemented by Robert Rae and Allan Ramsay in Edinburgh, on a research-council funded project. That version introduced caged address spaces, some compile-time syntactic typing as well as some pattern matching constructs for use with a variety of data-structures.
In parallel with that Steve Hardy at Sussex University implemented a subset of POP-2, which he called POP-11 which ran on a DEC PDP-11/40 computer. It was originally designed to run on the DEC operating system RSX-11D, in time-shared mode for teaching, but that caused so many problems that an early version of Unix was installed and used instead. That version of Pop-11 was written in Unix assembler, and code was incrementally compiled to an intermediate byte code which was interpreted. That port was completed around 1976 and as a result Pop-11 was used in several places for teaching. In order to support its teaching function many of the syntactic features of POP-2 were modified, e.g. replacing function... end with define... enddefine and adding a wider variety of looping constructs with closing brackets to match their opening brackets instead of the use of close for all loops in POP-2. Pop-11 also introduced a for list structures, making it much easier to teach AI programming.
Around 1980 Pop-11 was ported to a VAX-11/780 computer by Steve Hardy and John Gibson, and soon after that it was replaced by a full incremental compiler. The existence of the compiler and all its subroutines at run time made it possible to support far richer language extensions than were possible with Macros, and as a result Pop-11 was used ) to produce an implementation of Prolog, using the standard syntax of Prolog, and the combined system became known as Poplog, to which Common Lisp and Standard ML were later added. This version was later ported to a variety of machines and operating systems and as a result Pop-11 became the dominant dialect of POP-2, still available in the Poplog system.
Around 1986 a new AI company Cognitive Applications Ltd., collaborated with members of Sussex university to produce a variant of Pop-11 called AlphaPop running on Apple Mac computers, with integrated graphics. This was used for a number of commercial projects, as well as being used for teaching AI programming in several universities. The fact that it was implemented in an early dialect of C, using an idiosyncratic compiler made it very hard to maintain and upgrade to new versions of the Mac operating system. In addition to this, AlphaPop was not "32-bit clean" due to the use of high address bits as "tag bits" to signify the type of objects, which was incompatible with the use of memory above 8Mb on later Macintoshes.