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!
===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
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)