34
35:- module(foldnl,
36 [ foldnl/4,
37 foldnl/5,
38 foldnl/6,
39 foldnl/7,
40 foldnl/8,
41 foldnl/9
42 ]). 43
44:- meta_predicate
45 foldnl(3, +, +, -),
46 foldnl(4, +, +, +, -),
47 foldnl(5, +, +, +, +, -),
48 foldnl(6, +, +, +, +, +, -),
49 foldnl(7, +, +, +, +, +, +, -),
50 foldnl(8, +, +, +, +, +, +, +, -).
59foldnl(Goal, List) -->
60 foldnl_(List, Goal).
61
62foldnl_([], _) -->
63 !.
64foldnl_([H|T], Goal) -->
65 !,
66 foldnl_(H, Goal),
67 foldnl_(T, Goal).
68foldnl_(E, Goal) -->
69 call(Goal, E).
70
71foldnl(Goal, List1, List2) -->
72 foldnl_(List1, List2, Goal).
73
74foldnl_([], [], _) -->
75 !.
76foldnl_([H1|T1], [H2|T2], Goal) -->
77 !,
78 foldnl_(H1, H2, Goal),
79 foldnl_(T1, T2, Goal).
80foldnl_(E1, E2, Goal) -->
81 call(Goal, E1, E2).
82
83foldnl(Goal, List1, List2, List3) -->
84 foldnl_(List1, List2, List3, Goal).
85
86foldnl_([], [], [], _) -->
87 !.
88foldnl_([H1|T1], [H2|T2], [H3|T3], Goal) -->
89 !,
90 foldnl_(H1, H2, H3, Goal),
91 foldnl_(T1, T2, T3, Goal).
92foldnl_(E1, E2, E3, Goal) -->
93 call(Goal, E1, E2, E3).
94
95foldnl(Goal, List1, List2, List3, List4) -->
96 foldnl_(List1, List2, List3, List4, Goal).
97
98foldnl_([], [], [], [], _) -->
99 !.
100foldnl_([H1|T1], [H2|T2], [H3|T3], [H4|T4], Goal) -->
101 !,
102 foldnl_(H1, H2, H3, H4, Goal),
103 foldnl_(T1, T2, T3, T4, Goal).
104foldnl_(E1, E2, E3, E4, Goal) -->
105 call(Goal, E1, E2, E3, E4).
106
107foldnl(Goal, List1, List2, List3, List4, List5) -->
108 foldnl_(List1, List2, List3, List4, List5, Goal).
109
110foldnl_([], [], [], [], [], _) -->
111 !.
112foldnl_([H1|T1], [H2|T2], [H3|T3], [H4|T4], [H5|T5], Goal) -->
113 !,
114 foldnl_(H1, H2, H3, H4, H5, Goal),
115 foldnl_(T1, T2, T3, T4, T5, Goal).
116foldnl_(E1, E2, E3, E4, E5, Goal) -->
117 call(Goal, E1, E2, E3, E4, E5).
118
119foldnl(Goal, List1, List2, List3, List4, List5, List6) -->
120 foldnl_(List1, List2, List3, List4, List5, List6, Goal).
121
122foldnl_([], [], [], [], [], [], _) -->
123 !.
124foldnl_([H1|T1], [H2|T2], [H3|T3], [H4|T4], [H5|T5], [H6|T6], Goal) -->
125 !,
126 foldnl_(H1, H2, H3, H4, H5, H6, Goal),
127 foldnl_(T1, T2, T3, T4, T5, T6, Goal).
128foldnl_(E1, E2, E3, E4, E5, E6, Goal) -->
129 call(Goal, E1, E2, E3, E4, E5, E6)