diff --git a/library/expand_macros.yap b/library/expand_macros.yap index feb8ed91a..b3712fa6d 100644 --- a/library/expand_macros.yap +++ b/library/expand_macros.yap @@ -12,26 +12,6 @@ :- multifile user:goal_expansion/3. -user:goal_expansion(maplist(Meta, ListIn, ListOut), Mod, Goal) :- - goal_expansion_allowed, - callable(Meta), - !, - aux_preds(Meta, MetaVars, Pred, PredVars, Proto, Mod, Module), - % the new goal - pred_name(maplist, 3, Proto, GoalName), - append(MetaVars, [ListIn, ListOut], GoalArgs), - Goal =.. [GoalName|GoalArgs], - % the new predicate declaration - HeadPrefix =.. [GoalName|PredVars], - append_args(HeadPrefix, [[], []], Base), - append_args(HeadPrefix, [[In|Ins], [Out|Outs]], RecursionHead), - append_args(Pred, [In, Out], Apply), - append_args(HeadPrefix, [Ins, Outs], RecursiveCall), - compile_aux([ - Base, - (RecursionHead :- Apply, RecursiveCall) - ], Module). - user:goal_expansion(checklist(Meta, List), Mod, Goal) :- goal_expansion_allowed, callable(Meta), @@ -72,6 +52,27 @@ user:goal_expansion(maplist(Meta, List), Mod, Goal) :- (RecursionHead :- Apply, RecursiveCall) ], Module). +user:goal_expansion(maplist(Meta, ListIn, ListOut), Mod, Goal) :- + goal_expansion_allowed, + callable(Meta), + !, + aux_preds(Meta, MetaVars, Pred, PredVars, Proto, Mod, Module), + % the new goal + pred_name(maplist, 3, Proto, GoalName), + append(MetaVars, [ListIn, ListOut], GoalArgs), + Goal =.. [GoalName|GoalArgs], + writeln(g:Goal), + % the new predicate declaration + HeadPrefix =.. [GoalName|PredVars], + append_args(HeadPrefix, [[], []], Base), + append_args(HeadPrefix, [[In|Ins], [Out|Outs]], RecursionHead), + append_args(Pred, [In, Out], Apply), + append_args(HeadPrefix, [Ins, Outs], RecursiveCall), + compile_aux([ + Base, + (RecursionHead :- Apply, RecursiveCall) + ], Module). + user:goal_expansion(maplist(Meta, L1, L2, L3), Mod, Goal) :- goal_expansion_allowed, callable(Meta), @@ -460,11 +461,10 @@ aux_preds(Meta, MetaVars, Pred, PredVars, Proto, Module, Module) :- Proto =.. [F|ProtoArgs]. aux_args([], [], [], [], []). -aux_args([Arg|Args], [Arg|MVars], [PVar|PArgs], [PVar|PVars], ['_'|ProtoArgs]) :- - var(Arg), - !, - aux_args(Args, MVars, PArgs, PVars, ProtoArgs). aux_args([Arg|Args], MVars, [Arg|PArgs], PVars, [Arg|ProtoArgs]) :- + ground(Arg), !, + aux_args(Args, MVars, PArgs, PVars, ProtoArgs). +aux_args([Arg|Args], [Arg|MVars], [PVar|PArgs], [PVar|PVars], ['_'|ProtoArgs]) :- aux_args(Args, MVars, PArgs, PVars, ProtoArgs). pred_name(Macro, Arity, Proto, Name) :-