-
Notifications
You must be signed in to change notification settings - Fork 135
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
Different results with and without { true }
in a DCG
#2809
Comments
This is surprising bug, I think there is a problem with attributed variables unification. For example if you rewrite last 4 cbor_minor_value(24, val(x1, V), B, C) :- numbytes_number(1,V,B,C).
cbor_minor_value(25, val(x2, V), B, C) :- numbytes_number(2,V,B,C).
cbor_minor_value(26, val(x4, V), B, C) :- numbytes_number(4,V,B,C).
cbor_minor_value(27, val(x8, V), B, C) :- numbytes_number(8,V,B,C). Them test fails, but if you rewrite them as: cbor_minor_value(24, val(x1, V), B, C) :- B=D, numbytes_number(1,V,D,C).
cbor_minor_value(25, val(x2, V), B, C) :- B=D, numbytes_number(2,V,D,C).
cbor_minor_value(26, val(x4, V), B, C) :- B=D, numbytes_number(4,V,D,C).
cbor_minor_value(27, val(x8, V), B, C) :- B=D, numbytes_number(8,V,D,C). Then suddenly all tests pass. 🤔 |
Please do narrow down the problem to the very smallest program possible. Here is what I obtained by stepwise reducing your program, removing everything unnecessary:
So it is unrelated to |
Thanks! I'm adding 3 tests more. main3 :-
freeze(Minor,true),
cbor_minor_value3(Minor, []).
main4 :-
freeze(Minor,true),
cbor_minor_value4(Minor, []).
main5 :-
freeze(Minor,true),
cbor_minor_value5(Minor, []).
cbor_minor_value3(24, S0) :- numbytes_number(1, S1), S0=S1.
cbor_minor_value4(24, S0) :- true, numbytes_number(1, S0).
cbor_minor_value5(24, S0) :- numbytes_number(1, S0), true.
numbytes_number(_, []).
/*
?- main3.
true. % expected
?- main4.
true. % expected
?- main5.
false, unexpected.
true. % expected, but not found
*/ |
Another version that shows that the module name of the attribute is involved:
|
I just confirmed that this is the same problem as #2706. |
I have a DCG (
cbor_minor_value//2
), that in some cases only unify arguments,and in another cases it immediately calls another DCG (
numbytes_number//2
) and return.The predicate by itself works fine.
But when I call it from another predicate (
cbor_item//1
), it always fails at callingnumbytes_number//2
, even though a solution exists.If we add any predicate (such as
{ true }
or[]
), before or after callingnumbytes_number//2
, it starts to behave as expected.I don't know why that is happening.
I use
library(clpz)
to implementnumbytes_number//2
.There is the minimal file with a test case.
min-cbor.pl.txt
It is enough for
main/0
to succeed.The test file is a modified version of cbor.pl.
This problem was first mentioned in #2800.
My
scryer-prolog
version:The text was updated successfully, but these errors were encountered: