maplist/6
This commit is contained in:
parent
1e7ee487b6
commit
f1066036ff
@ -15,6 +15,7 @@
|
|||||||
maplist/3,
|
maplist/3,
|
||||||
maplist/4,
|
maplist/4,
|
||||||
maplist/5,
|
maplist/5,
|
||||||
|
maplist/6,
|
||||||
checklist/2,
|
checklist/2,
|
||||||
checknodes/2,
|
checknodes/2,
|
||||||
convlist/3,
|
convlist/3,
|
||||||
@ -52,6 +53,7 @@
|
|||||||
maplist(2,+,-),
|
maplist(2,+,-),
|
||||||
maplist(3,+,+,-),
|
maplist(3,+,+,-),
|
||||||
maplist(4,+,+,+,-),
|
maplist(4,+,+,+,-),
|
||||||
|
maplist(5,+,+,+,+,-),
|
||||||
convlist(2,+,-),
|
convlist(2,+,-),
|
||||||
convlist(3,?,?,?),
|
convlist(3,?,?,?),
|
||||||
mapnodes(2,+,-),
|
mapnodes(2,+,-),
|
||||||
@ -287,7 +289,8 @@ checklist(Pred, [In|ListIn]) :-
|
|||||||
checklist(Pred, ListIn).
|
checklist(Pred, ListIn).
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@pred maplist(: Pred, ? ListIn)
|
@pred
|
||||||
|
ist(: Pred, ? ListIn)
|
||||||
|
|
||||||
Applies predicate _Pred_( _El_ ) to all
|
Applies predicate _Pred_( _El_ ) to all
|
||||||
elements _El_ of _ListIn_.
|
elements _El_ of _ListIn_.
|
||||||
@ -339,6 +342,18 @@ maplist(Pred, [A1|L1], [A2|L2], [A3|L3], [A4|L4]) :-
|
|||||||
call(Pred, A1, A2, A3, A4),
|
call(Pred, A1, A2, A3, A4),
|
||||||
maplist(Pred, L1, L2, L3, L4).
|
maplist(Pred, L1, L2, L3, L4).
|
||||||
|
|
||||||
|
/**
|
||||||
|
@pred maplist(: Pred, ? L1, ? L2, ? L3, ? L4, ? L5)
|
||||||
|
|
||||||
|
_L1_, _L2_, _L3_, _L4_ and _L5_ are such that
|
||||||
|
`call( _Pred_, _A1_, _A2_, _A3_, _A4_,_A5_)` holds
|
||||||
|
for every corresponding element in lists _L1_, _L2_, _L3_, _L4_ and _L5_.
|
||||||
|
*/
|
||||||
|
maplist(_, [], [], [], [], []).
|
||||||
|
maplist(Pred, [A1|L1], [A2|L2], [A3|L3], [A4|L4], [A5|L5]) :-
|
||||||
|
call(Pred, A1, A2, A3, A4, A5),
|
||||||
|
maplist(Pred, L1, L2, L3, L4, L5).
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@pred convlist(: Pred, + ListIn, ? ListOut)
|
@pred convlist(: Pred, + ListIn, ? ListOut)
|
||||||
|
|
||||||
@ -793,6 +808,27 @@ goal_expansion(maplist(Meta, L1, L2, L3, L4), Mod:Goal) :-
|
|||||||
(RecursionHead :- Apply, RecursiveCall)
|
(RecursionHead :- Apply, RecursiveCall)
|
||||||
], Mod).
|
], Mod).
|
||||||
|
|
||||||
|
goal_expansion(maplist(Meta, L1, L2, L3, L4, L5), Mod:Goal) :-
|
||||||
|
goal_expansion_allowed,
|
||||||
|
callable(Meta),
|
||||||
|
prolog_load_context(module, Mod),
|
||||||
|
aux_preds(Meta, MetaVars, Pred, PredVars, Proto),
|
||||||
|
!,
|
||||||
|
% the new goal
|
||||||
|
pred_name(maplist, 6, Proto, GoalName),
|
||||||
|
append(MetaVars, [L1, L2, L3, L4, L5], GoalArgs),
|
||||||
|
Goal =.. [GoalName|GoalArgs],
|
||||||
|
% the new predicate declaration
|
||||||
|
HeadPrefix =.. [GoalName|PredVars],
|
||||||
|
append_args(HeadPrefix, [[], [], [], [], []], Base),
|
||||||
|
append_args(HeadPrefix, [[A1|A1s], [A2|A2s], [A3|A3s], [A4|A4s], [A5|A5s]], RecursionHead),
|
||||||
|
append_args(Pred, [A1, A2, A3, A4, A5], Apply),
|
||||||
|
append_args(HeadPrefix, [A1s, A2s, A3s, A4s, A5s], RecursiveCall),
|
||||||
|
compile_aux([
|
||||||
|
Base,
|
||||||
|
(RecursionHead :- Apply, RecursiveCall)
|
||||||
|
], Mod).
|
||||||
|
|
||||||
goal_expansion(selectlist(Meta, ListIn, ListOut), Mod:Goal) :-
|
goal_expansion(selectlist(Meta, ListIn, ListOut), Mod:Goal) :-
|
||||||
goal_expansion_allowed,
|
goal_expansion_allowed,
|
||||||
callable(Meta),
|
callable(Meta),
|
||||||
|
@ -83,11 +83,10 @@ pred_name(Macro, Arity, _ , Name) :-
|
|||||||
prolog_load_context(term_position, Pos),
|
prolog_load_context(term_position, Pos),
|
||||||
stream_position_data( line_count, Pos, Line ), !,
|
stream_position_data( line_count, Pos, Line ), !,
|
||||||
transformation_id(Id),
|
transformation_id(Id),
|
||||||
atomic_concat(['$$$ for ',Macro,'/',Arity,', line ',Line,' in ',File,' ',Id], Name).
|
atomic_concat(['$$$ for ',Macro,'/',Arity,', line ',Line,' in ',File,'(',P,') #',Id], Name).
|
||||||
pred_name(Macro, Arity, _ , Name) :-
|
pred_name(Macro, Arity, P , Name) :-
|
||||||
transformation_id(Id),
|
transformation_id(Id),
|
||||||
stop_low_level_trace,
|
atomic_concat(['$$$__expansion__ for ',Macro,'/',Arity,'(',P,') #',Id], Name).
|
||||||
atomic_concat(['$$$__expansion__ for ',Macro,'/',Arity,' ',Id], Name).
|
|
||||||
|
|
||||||
transformation_id(Id) :-
|
transformation_id(Id) :-
|
||||||
retract(number_of_expansions(Id)),
|
retract(number_of_expansions(Id)),
|
||||||
|
Reference in New Issue
Block a user