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

Unexpected loop with goal expansion #2705

Open
notoria opened this issue Dec 13, 2024 · 1 comment
Open

Unexpected loop with goal expansion #2705

notoria opened this issue Dec 13, 2024 · 1 comment

Comments

@notoria
Copy link
Contributor

notoria commented Dec 13, 2024

I tried this code:

?- [user].
:- use_module(library(format), [portray_clause/2]).
:- use_module(library(lists), [append/3]).

is_convertible_term(T) :-
    catch((! ; T), error(type_error(callable,_),_), false).

is_body(T) :-
    \+ \+ (
        term_variables(T, Vs),
        append(Vs, _, [0|Vs]),
        is_convertible_term(T)
    ).

goal_expansion(G, _) :-
    portray_clause(user_error, goal-G),
    false.
goal_expansion(G, call(G)) :-
    \+ is_body(G).

head :-
    call((a, b)),
    call(','(c), d),
    call(',', e, f).

The expansion loops because invalid bodies are introduced and Scryer expands dynamic goals at compile-time:

goal-(call((a,b)),call(','(c),d),call(',',e,f)).
goal-call((a,b)).
goal-(a,b).
goal-a.
goal-b.
goal-(call(','(c),d),call(',',e,f)).
goal-call(','(c),d).
goal-(c,A).
goal-c.
goal-call(',',e,f).
goal-(A,B).

Maybe goal_expansion(G, call(G)) :- \+ is_body(G) is expected to loop since dynamic goals are expanded but the body of head/0 is valid, it should not loop here.

@notoria
Copy link
Contributor Author

notoria commented Dec 14, 2024

Unexpected:

?- [user].
goal_expansion(a(A,B), b) :-
    var(B).

:- dynamic(test/0).
test :-
    call(a(_, 0)),
    call(a(_), 1),
    call(a, _, 2).
% Warning: singleton variables A at line 1 of user

?- clause(test, G).
   G = (call(user:a(_A,0)),call(user:b,1),call(user:b,_B,2)). % unexpected.
?-

Expected: G = (call(user:a(_A,0)),call(user:a,1),call(user:a,_B,2)).

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

1 participant