Re: freeze/2 and nb_setarg/3 interaction
Michael Ben Yosef <[email protected]> Fri, 11 Apr 2014 10:19:16 +0200
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CABnaNcpWFSU7rBVRAjc3wcORVY+H3xAPYT1ecEOD06rsWDiRHw@mail.gmail.com> |
Michael,
> Somehow nb_setarg/3 is being undone on backtracking when freeze/2 is
> involved.
I could be misunderstanding this, but I don't think freeze/2 is the
culprit here. I think nb_setarg/3 (and setarg/3, see below) are
fundamentally dangerous (broken, even) when the arg being assigned to
is a variable. Consider the following:
correct2 :-
X = [_|_],
( nb_setarg(1, X, a),
writeln(X),
fail
; writeln(X)
).
broken2 :-
X = [H|_],
( H = a,
nb_setarg(1, X, a),
writeln(X),
fail
; writeln(X)
).
?- correct2.
[a|_G2435]
[a|_G2435]
true.
?- broken2.
[a|_G2271]
[_G2270|_G2271]
true.
Clearly, adding in the "H = a" goal has caused the binding of that
argument to be undone on backtracking. Maybe your bug is an instance
of this problem?
This is reminiscent of a setarg/3 bug I reported a while ago:
https://lists.iai.uni-bonn.de/pipermail/swi-prolog/2013/011602.html
In any case, maybe Jan's answer there - that this is basically
expected and unfixable - can shed some light on your problem.
Hope that helps!
Michael