]> Repositorios git - scryer-prolog.git/commitdiff
leave the expansion of incomplete goals in meta-predicates to call/N (#967, #970)
authorMark Thom <[email protected]>
Wed, 19 May 2021 20:07:46 +0000 (14:07 -0600)
committerMark Thom <[email protected]>
Wed, 19 May 2021 20:07:46 +0000 (14:07 -0600)
src/lib/reif.pl
src/loader.pl
src/toplevel.pl

index 092f93ec4663a20184a3f9a4586b385e39c4a0d6..b8d4bbaad70b3c2d9edc63e7fb2d92512215b8d6 100644 (file)
@@ -4,7 +4,7 @@
 
 :- use_module(library(dif)).
 
-:- meta_predicate if_(0, 0, 0).
+:- meta_predicate if_(1, 0, 0).
 
 if_(If_1, Then_0, Else_0) :-
     call(If_1, T),
index 7915ae3747949036fcdcd7890ddda8b31560de9c..f231ffd16bb05430a6fcbf78cb4f30defa1acb5e 100644 (file)
@@ -586,10 +586,16 @@ strip_module(Goal, M, G) :-
 expand_subgoal(UnexpandedGoals, MS, Module, ExpandedGoals, HeadVars) :-
     (  var(UnexpandedGoals) ->
        UnexpandedGoals = ExpandedGoals
-    ;  goal_expansion(UnexpandedGoals, Module, UnexpandedGoals1),
-       (  Module \== user ->
-          goal_expansion(UnexpandedGoals1, user, Goals)
-       ;  Goals = UnexpandedGoals1
+    ;  (  MS == 0 ->
+          % only expand complete goals. call/N will take care of incomplete goals
+          % by calling goal expansion after it is supplied the remaining arguments.
+          (  goal_expansion(UnexpandedGoals, Module, UnexpandedGoals1),
+             (  Module \== user ->
+                goal_expansion(UnexpandedGoals1, user, Goals)
+             ;  Goals = UnexpandedGoals1
+             )
+          )
+       ;  Goals = UnexpandedGoals
        ),
        (  inner_meta_specs(MS, Goals, _, MetaSpecs) ->
           expand_module_names(Goals, MetaSpecs, Module, ExpandedGoals, HeadVars)
@@ -740,14 +746,6 @@ thread_goals(Goals0, Goals1, Hole, Functor) :-
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
-call_clause(M:G1, G0) :-
-    functor(G1, F, _),
-    atom(F),
-    atom(M),
-    F \== [],
-    !,
-    expand_goal(M:G1, M, G0).
-
 % The '$call' functor is an escape hatch from goal expansion. So far,
 % it is used only to avoid infinite recursion into expand_goal/3.
 
@@ -770,11 +768,15 @@ call_clause('$call'(G), G0) :-
     ).
 
 call_clause(G, G0) :-
-    functor(G, F, _),
+    strip_module(G, M, G1),
+    functor(G1, F, _),
     atom(F),
     F \== [],
-    load_context(M),
-    expand_goal(M:G, M, G0).
+    (  var(M) ->
+       load_context(M)
+    ;  true
+    ),
+    expand_goal(M:G1, M, G0).
 
 
 call(G) :-
@@ -786,16 +788,6 @@ call(G) :-
     ).
 
 
-call_clause(M:G1, Args, _, G0) :-
-    atom(M),
-    G1 =.. [F | As],
-    atom(F),
-    F \== [],
-    !,
-    append(As, Args, As1),
-    G2 =.. [F | As1],
-    expand_goal(M:G2, M, G0).
-
 call_clause('$call'(G1), Args, N, G0) :-
     (  var(G1),
        instantiation_error(call/N)
@@ -819,10 +811,14 @@ call_clause('$call'(G1), Args, N, G0) :-
     ).
 
 call_clause(G, Args, _, G0) :-
-    G =.. [F | As],
+    strip_module(G, M, G1),
+    G1 =.. [F | As],
     atom(F),
     F \== [],
-    load_context(M),
+    (  var(M) ->
+       load_context(M)
+    ;  true
+    ),
     append(As, Args, As1),
     G2 =.. [F | As1],
     expand_goal(M:G2, M, G0).
index 0ddec4314234ac8df8d703045997e4b2d36720bf..e45de8d730994462e06cbceb82c5761e36b4e80d 100644 (file)
@@ -171,7 +171,11 @@ submit_query_and_print_results_(_, _) :-
 
 
 submit_query_and_print_results(Term0, VarList) :-
-    expand_goal(call(Term0), user, call(Term)),
+    (  functor(Term0, call, _) ->
+       Term = Term0 % prevent pre-mature expansion of incomplete goal
+                    % in the first argument, which is done by call/N
+    ;  expand_goal(call(Term0), user, call(Term))
+    ),
     setup_call_cleanup(bb_put('$first_answer', true),
                        submit_query_and_print_results_(Term, VarList),
                        bb_put('$first_answer', false)).