trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
252 stars 11 forks source link

Meta predicate goal expansion #518

Closed infradig closed 3 months ago

infradig commented 3 months ago

Taken from a Scryer issue, but Trealla exhibits an extra problem.

:- use_module(library(dcgs)).

user:goal_expansion(a(Cs0,Cs), b(Cs0,Cs)).

:- dynamic(p/2).

:- meta_predicate(g(2,?,?)).

p --> a.
p --> g(a).
p --> g(g(a)).
p --> g((g(a),[])).

Only the first a get expanded to b...

?- clause(p(Cs0, Cs), Body).
   Body = b(Cs0,Cs)
;  Body = g(a,Cs0,Cs)
;  Body = g(g(a),Cs0,Cs)
;  Body = g((g(a),[]),Cs0,Cs).
?- 
infradig commented 3 months ago

Partial fix...

?- clause(p(Cs0, Cs), Body).
   Body = b(Cs0,Cs)
;  Body = g(b,Cs0,Cs)
;  Body = g(g(b),Cs0,Cs)
;  Body = g((g(a),[]),Cs0,Cs).
?- 

Now roughly equivalent to the Scryer bug.

infradig commented 3 months ago

Now exactly equivalent to Scryer #2366 with needing an explicit meta_predicate directive for (,)/2 I guess due to module confusion...

$ tpl x.pl
?- clause(p(Cs0, Cs), Body).
   Body = b(Cs0,Cs)
;  Body = g(b,Cs0,Cs)
;  Body = g(g(b),Cs0,Cs)
;  Body = g((g(b),[]),Cs0,Cs).
?-