fix maplist and friends to handle non-var non-ground arguments (obs from Jose Santos).
This commit is contained in:
parent
c5ba7e3854
commit
3fff188701
@ -12,26 +12,6 @@
|
|||||||
|
|
||||||
:- multifile user:goal_expansion/3.
|
:- 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) :-
|
user:goal_expansion(checklist(Meta, List), Mod, Goal) :-
|
||||||
goal_expansion_allowed,
|
goal_expansion_allowed,
|
||||||
callable(Meta),
|
callable(Meta),
|
||||||
@ -72,6 +52,27 @@ user:goal_expansion(maplist(Meta, List), Mod, Goal) :-
|
|||||||
(RecursionHead :- Apply, RecursiveCall)
|
(RecursionHead :- Apply, RecursiveCall)
|
||||||
], Module).
|
], 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) :-
|
user:goal_expansion(maplist(Meta, L1, L2, L3), Mod, Goal) :-
|
||||||
goal_expansion_allowed,
|
goal_expansion_allowed,
|
||||||
callable(Meta),
|
callable(Meta),
|
||||||
@ -460,11 +461,10 @@ aux_preds(Meta, MetaVars, Pred, PredVars, Proto, Module, Module) :-
|
|||||||
Proto =.. [F|ProtoArgs].
|
Proto =.. [F|ProtoArgs].
|
||||||
|
|
||||||
aux_args([], [], [], [], []).
|
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]) :-
|
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).
|
aux_args(Args, MVars, PArgs, PVars, ProtoArgs).
|
||||||
|
|
||||||
pred_name(Macro, Arity, Proto, Name) :-
|
pred_name(Macro, Arity, Proto, Name) :-
|
||||||
|
Reference in New Issue
Block a user