SWI-Prolog / issues

Dummy repository for issue tracking
7 stars 3 forks source link

DCGs, call/1, clpfd incorrect goal expansion #119

Closed UWN closed 1 year ago

UWN commented 1 year ago

9.1.1, but also in current swish (except for the last which is rejected there)

?- As = [], phrase([a|As],[a,b],Bs).
As = [],
Bs = [b].

?- use_module(library(clpfd)).
true.

?- As = [], phrase([a|As],[a,b],Bs).
false, unexpected.

?- As = [], call(phrase([a|As],[a,b],Bs)).
false, unexpected.

?- As = [], phrase([a|As],[a,b],Bs)=G_0, G_0.
As = [],
Bs = [b],
G_0 = phrase([a], [a, b], [b]).

Thus:

  1. goal expansion of phrase/3 is incorrect
  2. goal expansion is overzealous, in particular call/1 is inspected too early (which would be OK only as long as behaviour would be exactly the same as with no premature inspection)

And then (independently), there is:

?- phrase([a|As],Bs).
As = [],
Bs = [a], unexpected ;
As = [_A],
Bs = [a, _A] , unexpected .

?- use_module(library(clpfd)).
true.

?- phrase([a|As],Bs).
As = [],
Bs = [a], unexpected.

?- phrase(As,Bs).
ERROR: Arguments are not sufficiently instantiated % expected
JanWielemaker commented 1 year ago

Thanks. It is all the same bug: goal expansion for phrase/3 defined in library(apply_macros) was too greedy for partial terminals. Should be fixed with SWI-Prolog/swipl-devel@8d0bb1ccfd71629ec4ecf60d2b24856bb1af51b3. At least, all test still pass and the "unexpected" above now pass.