Ulrich Neumerkel's lambda expressions.

This commit is contained in:
Vitor Santos Costa 2010-08-04 23:26:50 +01:00
parent b3b61bcecc
commit 410c4c96d5
3 changed files with 83 additions and 3 deletions

View File

@ -16,7 +16,8 @@
<h1>Changes in YAP-6</h1>
<h2>Yap-6.0.7:</h2>
<ul> FIXED: make install clpqr was broken if we used local install_sh .</li>
<ul>
<li> FIXED: make install in clpqr was broken if we used local install_sh .</li>
<li> DELETE: atan/2 arithmetic function, use atan2/2 instead (WG17).</li>
<li> FIXED: compilation in Solaris was broken because of conflict in
declaration of gethostname.</li>

View File

@ -198,6 +198,7 @@ Subnodes of Library
* AVL Trees:: Predicates to add and lookup balanced binary trees.
* Heaps:: Labelled binary tree where the key of each node is less
than or equal to the keys of its children.
* Lambda:: Ulrich Neumerkel's Lambda Library
* LineUtilities:: Line Manipulation Utilities
* Lists:: List Manipulation
* MapList:: SWI-Compatible Apply library.
@ -8465,6 +8466,7 @@ Library, Extensions, Built-ins, Top
* Heaps:: Labelled binary tree where the key of each node is less
than or equal to the keys of its children.
* LAM:: LAM MPI
* Lambda:: Ulrich Neumerkel's Lambda Library
* Lists:: List Manipulation
* LineUtilities:: Line Manipulation Utilities
* MapList:: SWI-Compatible Apply library.
@ -12503,7 +12505,7 @@ The path @var{Path} is a path starting at vertex @var{Vertex} in graph
@end table
@node UnDGraphs, LAM , DGraphs, Library
@node UnDGraphs, Lambda , DGraphs, Library
@section Undirected Graphs
@cindex undirected graphs
@ -12599,7 +12601,83 @@ directed graph @var{DGraph}.
@end table
@node LAM, , UnDGraphs, Library
@node Lambda, LAM, UnDGraphs, Library
@section Lambda Expressions
@cindex Lambda Expressions
This library, designed and implemented by Ulrich Neumerkel, provides
lambda expressions to simplify higher order programming based on @code{call/N}.
Lambda expressions are represented by ordinary Prolog terms. There are
two kinds of lambda expressions:
@example
Free+\X1^X2^ ..^XN^Goal
\X1^X2^ ..^XN^Goal
@end example
The second is a shorthand for@code{ t+\X1^X2^..^XN^Goal}, where @code{Xi} are the parameters.
@var{Goal} is a goal or continuation (Syntax note: @var{Operators} within @var{Goal}
require parentheses due to the low precedence of the @code{^} operator).
Free contains variables that are valid outside the scope of the lambda
expression. They are thus free variables within.
All other variables of @var{Goal} are considered local variables. They must
not appear outside the lambda expression. This restriction is
currently not checked. Violations may lead to unexpected bindings.
In the following example the parentheses around @code{X>3} are necessary.
@example
?- use_module(library(lambda)).
?- use_module(library(apply)).
?- maplist(\X^(X>3),[4,5,9]).
true.
@end example
In the following @var{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.
@example
?- Xs = [A,B], maplist(X+\Y^dif(X,Y), Xs).
Xs = [A, B],
dif(X, A),
dif(X, B).
?- Xs = [A,B], maplist(X+\dif(X), Xs).
Xs = [A, B],
dif(X, A),
dif(X, B).
@end example
The following queries are all equivalent. To see this, use
the fact @code{f(x,y)}.
@example
?- call(f,A1,A2).
?- call(\X^f(X),A1,A2).
?- call(\X^Y^f(X,Y), A1,A2).
?- call(\X^(X+\Y^f(X,Y)), A1,A2).
?- call(call(f, A1),A2).
?- call(f(A1),A2).
?- f(A1,A2).
A1 = x,
A2 = y.
@end example
Further discussions
at @url{http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hiord}.
@node LAM, , Lambda, Library
@section LAM
@cindex lam

View File

@ -44,6 +44,7 @@ PROGRAMS= \
$(srcdir)/gensym.yap \
$(srcdir)/hacks.yap \
$(srcdir)/heaps.yap \
$(srcdir)/lambda.pl \
$(srcdir)/lineutils.yap \
$(srcdir)/lists.yap \
$(srcdir)/nb.yap \