This commit is contained in:
Vítor Santos Costa
2014-12-24 15:32:29 +00:00
parent bc6bf8cdfd
commit 53877ad426
35 changed files with 856 additions and 1002 deletions

View File

@@ -46,21 +46,23 @@ official policies, either expressed or implied, of Ulrich Neumerkel.
This library provides lambda expressions to simplify higher order
programming based on call/N.
Lambda expressions are represented by ordinary Prolog terms.
There are two kinds of lambda expressions:
Lambda expressions are represented by ordinary Prolog terms.
There are two kinds of lambda expressions:
Free+\X1^X2^ ..^XN^Goal
~~~~
Free+\X1^X2^ ..^XN^Goal
\X1^X2^ ..^XN^Goal
~~~~
The second is a shorthand for t+\X1^X2^..^XN^Goal.
The second is a shorthand for t+\X1^X2^..^XN^Goal
Xi are the parameters.
+ _Xi_ are the parameters.
Goal is a goal or continuation. Syntax note: Operators within Goal
+ _Goal_ is a goal or continuation. Syntax note: Operators within Goal
require parentheses due to the low precedence of the ^ operator.
Free contains variables that are valid outside the scope of the lambda
+ _Free_ contains variables that are valid outside the scope of the lambda
expression. They are thus free variables within.
All other variables of Goal are considered local variables. They must
@@ -69,20 +71,20 @@ currently not checked. Violations may lead to unexpected bindings.
In the following example the parentheses around X>3 are necessary.
==
~~~~~
?- use_module(library(lambda)).
?- use_module(library(apply)).
?- maplist(\X^(X>3),[4,5,9]).
true.
==
~~~~~
In the following X is a variable that is shared by both instances of
In the following _X_ is a variable that is shared by both instances of
the lambda expression. The second query illustrates the cooperation of
continuations and lambdas. The lambda expression is in this case a
continuation expecting a further argument.
==
~~~~~
?- Xs = [A,B], maplist(X+\Y^dif(X,Y), Xs).
Xs = [A, B],
dif(X, A),
@@ -92,11 +94,11 @@ dif(X, B).
Xs = [A, B],
dif(X, A),
dif(X, B).
==
~~~~~
The following queries are all equivalent. To see this, use
the fact f(x,y).
==
~~~~~
?- call(f,A1,A2).
?- call(\X^f(X),A1,A2).
?- call(\X^Y^f(X,Y), A1,A2).
@@ -106,7 +108,7 @@ the fact f(x,y).
?- f(A1,A2).
A1 = x,
A2 = y.
==
~~~~~
Further discussions
http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hiord