I know that Prolog has no built-in binders for presentation, for example. λx (x=1)but I was wondering if they can be implemented. In some predicates, such as setof/3, the behavior is pretty close: a variable Xin the substitution of responses for the request
?- setof(X, member(X,[a,a,c]), Xs).
Xs = [a, c].
is unrelated, and we can give it meaning to our taste:
?- setof(X, member(X,[a,a,c]), Xs), X = b.
X = b,
Xs = [a, c].
But if we create earlier X, we lose decisions:
?- X = b, setof(X, member(X,[a,a,c]), Xs).
false.
I would like to setofbind X, i.e. for evaluation setof, it is Xtreated as a fresh variable. To make this more specific: is it possible to implement an implementation binding_setofsuch that
?- X = b, binding_setof(X, member(X,[a,a,c]), Xs).
X = b,
Xs = [a, c].
?
PS: I know languages like λProlog that were created to solve this problem, but I'm interested in the Prolog solution.
:
library(lambda). \X^setof(X, member(X,[a,c,c], Xs) call/N. Xs , . , format('~w',[Xs]) , . ,
?- call(\X^setof(X,member(X,[a,c,c]),Xs), _), X=b.
X = b.
,
?- X = b, call(\X^setof(X,member(X,[a,c,c]),Xs), _).
false.
. , lambda .