Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
POP-2
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Description== ===Stack=== POP-2's [[Syntax (programming languages)|syntax]] is [[ALGOL]]-like, except that [[Assignment (computer science)|assignments]] are in reverse order: instead of writing a := 3; one writes 3 -> a; The reason for this is that the language has explicit notion of an ''[[Stack (abstract data type)|operand stack]]''. Thus, the prior assignment can be written as two separate [[Statement (computer science)|statements]]: 3; which evaluates the value 3 and leaves it on the stack, and -> a; which pops the top value off the stack and assigns it to the [[Variable (computer science)|variable]] 'a'. Similarly, the function call f(x, y, z); can be written as x, y, z; f(); (commas and semicolons being largely interchangeable) or even x, y, z.f; or (x, y, z).f; Because of the [[Stack-oriented programming|stack-based]] paradigm, there is 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; are equivalent (use of {{code|close}}, as {{code|endif}} hadn't become a common {{code|end-of-if-clause}} notation yet). ===Arrays and doublet functions=== There are no special language constructs to create arrays or record structures as they are commonly understood: instead, these are created with the aid of special builtin functions, e.g., {{code|newarray}}<ref>{{Cite web |url=http://www.cs.bham.ac.uk/research/projects/poplog/doc/pophelp/newarray |title=Help Newarray |last1=Rubinstein |first1=Mark |last2=Sloman |first2=A. |date=October 1985 β April 1989 |website=University of Birmingham |access-date=22 March 2024}}</ref> (for arrays that can contain any type of item) and {{code|newanyarray}}<ref>{{Cite web |url=http://www.cs.bham.ac.uk/research/projects/poplog/doc/pophelp/newanyarray |title=Help Newanyarray |last1=Hardy |first1=Steven |last2=Williams |first2=John |last3=Sloman |first3=A. |date=January 1978 β April 1986 |website=University of Birmingham |access-date=22 March 2024}}</ref> to create restricted types of items. Thus, array element and record field accessors are simply special cases of a ''doublet function'': this is a function that had another function attached as its ''updater'',<ref>{{Cite web |url=http://www.cs.bham.ac.uk/research/projects/poplog/doc/pophelp/updater |title=Help Updater |last=Sloman |first=A. |date=April 1985 |website=University of Birmingham |access-date=21 March 2024}}</ref> which is called on the receiving side of an assignment. Thus, if the variable {{code|a}} contains an array, then 3 -> a(4); is equivalent to updater(a)(3, 4); the builtin function {{code|updater}} returning the updater of the doublet. Of course, {{code|updater}} is a doublet and can be used to change the updater component of a doublet. ===Functions=== Variables can hold values of any type, including functions, which are 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; are equivalent. An interesting operation on functions is [http://www.cs.bham.ac.uk/research/projects/poplog/doc/pophelp/partapply ''partial application''], (sometimes termed ''[[currying]]''). In partial application, some number of the rightmost arguments of the function (which are the last ones placed on the stack before the function is involved) are ''frozen'' to given values, to produce a new function of fewer arguments, which is a [[Closure (computer programming)|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 can be bound, for instance as vars less1squared; poly2(% 1, -2, 1%) -> less1squared; such that the expression less1squared(3) applies the closure of poly2 with three arguments frozen, to the argument 3, returning the square of (3 - 1), which is 4. The application of the partially applied function causes the frozen values (in this case 1, -2, 1) to be added to whatever is already on the stack (in this case 3), after which the original function poly2 is invoked. It then uses the top four items on the stack, producing the same result as poly2(3, 1, -2, 1) i.e. 1*3*3 + (-2)*3 + 1 ===Operator definition=== In POP-2, it was possible to define new operations (operators in modern terms).<ref>[https://www.cs.utexas.edu/~moore/best-ideas/pltp/POP-2-Reference-Manual.pdf POP-2 Reference Manual], page 217, and An Introduction to the Study of Programming Languages, by David William Barron, page 75</ref> vars operation 3 +*; lambda x y; x * x + y * y end -> nonop +* The first line declares a new operation +* with precedence (priority) 3. The second line creates a function f(x,y)=x*x+y*y, and assigns it to the newly declared operation +*.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)