Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiation confusion #2656

Open
flexoron opened this issue Nov 3, 2024 · 1 comment
Open

Instantiation confusion #2656

flexoron opened this issue Nov 3, 2024 · 1 comment

Comments

@flexoron
Copy link

flexoron commented Nov 3, 2024

?- use_module(library(freeze)).
   true.
?- [user].
:- module(b, [b/0]).
b:b.

?- freeze(X,(Y=Z)), freeze(Y,b:P), bagof(Y=Y,X=Y,[Z=Z]), P=b, X=true. % notice P=b
   error(instantiation_error,call/1).

?- freeze(X,(Y=Z,P=b)), freeze(Y,b:P), bagof(Y=Y,X=Y,[Z=Z]), X=true. % now P=b 'freeze-shifted'
   error(instantiation_error,call/1).

?- freeze(X,(Y=Z,P=b)), freeze(Y,b:P), bagof(Y=Y,X=Y,[Z=Z]), P=b, X=true. % both in place and it works, why?
   X = true, Y = true, Z = true, P = b.
?- 
A problem I see is that b:b is called twice:

?- [user].
:- module(b, [b/0]).
b:b :- write(trace),nl.

?- freeze(X,(Y=Z,P=b)), freeze(Y,b:P), bagof(Y=Y,X=Y,[Z=Z]), P=b, X=true.
trace
trace
   X = true, Y = true, Z = true, P = b.

% Four are better than two
?- freeze(X,(Y=Z,P=b)), freeze(Y,(P:P,P:P)), bagof(Y=Y,X=Y,[Z=Z]), P=b, X=true.
trace
trace
trace
trace
   X = true, Y = true, Z = true, P = b.
?-
@UWN
Copy link

UWN commented Nov 3, 2024

Shorter:

?- freeze(X,a),freeze(Y,b),X=Y.
   X = Y, freeze:freeze(X,(a,b)) % fine, one possible answer
|  X = Y, freeze:freeze(X,a), freeze:freeze(X, b). % another possible answer
?- freeze(X,a),freeze(Y,b), bagof(t,X=Y,_).
   X = Y, freeze:freeze(X,((a,a,b),b)), unexpected.
?- freeze(X,a),freeze(Y,b), setof(t,X=Y,_).
   X = Y, freeze:freeze(X,((a,a,b),b)), unexpected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants