32
33:- module(sicstus4_lists,
34 [ keys_and_values/3, 35 rev/2, 36 shorter_list/2, 37 append_length/4, 38 append_length/3, 39 prefix_length/3, 40 proper_prefix_length/3, 41 suffix_length/3, 42 proper_suffix_length/3, 43 sublist/5, 44 sublist/4, 45 sublist/3, 46 cons/3, 47 last/3, 48 head/2, 49 tail/2, 50 prefix/2, 51 proper_prefix/2, 52 suffix/2, 53 proper_suffix/2, 54 subseq/3, 55 subseq0/2, 56 subseq1/2, 57 scanlist/4, 58 scanlist/5, 59 scanlist/6, 60
61 62 63 64 is_list/1 65 ]). 66:- reexport('../../lists',
67 [ select/3,
68 selectchk/3,
69 append/2,
70 delete/3,
71 last/2,
72 73 74 75 list_to_set/2 as remove_dups,
76 nextto/3,
77 nth1/3,
78 nth1/4,
79 nth0/3,
80 nth0/4,
81 permutation/2,
82 proper_length/2,
83 reverse/2,
84 same_length/2,
85 select/4,
86 selectchk/4,
87 sum_list/2 as sumlist,
88 max_member/2,
89 min_member/2,
90 max_member/3,
91 min_member/3,
92 clumped/2
93 ]). 94:- reexport('../../apply',
95 [ maplist/2,
96 maplist/3,
97 maplist/4,
98 convlist/3,
99 exclude/3,
100 include/3,
101 partition/5
102 ]). 103:- reexport('../../clp/clpfd', [transpose/2]). 104:- reexport('../sicstus/lists', [same_length/3]). 105:- use_module(library(pairs), [pairs_keys_values/3]). 106
107:- multifile sicstus4:rename_module/2. 108
109sicstus4:rename_module(lists, sicstus4_lists).
144keys_and_values(Pairs, Keys, Values) :-
145 pairs_keys_values(Pairs, Keys, Values).
152rev(List, Reversed) :- rev_(List, [], Reversed).
153rev_([], Reversed, Reversed).
154rev_([Head|Tail], RevTail, Reversed) :-
155 rev_(Tail, [Head|RevTail], Reversed).
164shorter_list([], [_|_]).
165shorter_list([_|ShortTail], [_|LongTail]) :-
166 shorter_list(ShortTail, LongTail).
167
168
170
171append_length(Prefix, Suffix, List, Length) :-
172 append(Prefix, Suffix, List),
173 length(Prefix, Length).
174
175append_length(Suffix, List, Length) :-
176 append_length(_, Suffix, List, Length).
177
178prefix_length(List, Prefix, Length) :-
179 prefix(List, Prefix),
180 length(Prefix, Length).
181
182proper_prefix_length(List, Prefix, Length) :-
183 proper_prefix(List, Prefix),
184 length(Prefix, Length).
185
186suffix_length(List, Suffix, Length) :-
187 suffix(List, Suffix),
188 length(Suffix, Length).
189
190proper_suffix_length(List, Suffix, Length) :-
191 proper_suffix(List, Suffix),
192 length(Suffix, Length).
193
194
195sublist(Whole, Part, Before, Length, After) :-
196 append(Prefix, Tail, Whole),
197 append(Part, Suffix, Tail),
198 length(Prefix, Before),
199 length(Part, Length),
200 length(Suffix, After).
201
202sublist(Whole, Part, Before, Length) :-
203 sublist(Whole, Part, Before, Length, _).
204
205sublist(Whole, Part, Before) :-
206 sublist(Whole, Part, Before, _, _).
207
208
209cons(Head, Tail, [Head|Tail]).
210last(Fore, Last, List) :- append(Fore, [Last], List).
211head([Head|_], Head).
212tail([_|Tail], Tail).
220prefix(List, Prefix) :-
221 append(Prefix, _, List).
227proper_prefix(List, Prefix) :-
228 prefix(List, Prefix),
229 Prefix \== List.
236suffix(List, List).
237suffix([_|Tail], Suffix) :-
238 suffix(Tail, Suffix).
244proper_suffix([_|Tail], Suffix) :-
245 suffix(Tail, Suffix).
256:- meta_predicate scanlist(3, ?, ?, ?). 257scanlist(Pred, Xs, V1, V) :- foldl(Pred, Xs, V1, V).
258:- meta_predicate scanlist(4, ?, ?, ?, ?). 259scanlist(Pred, Xs, Ys, V1, V) :- foldl(Pred, Xs, Ys, V1, V).
260:- meta_predicate scanlist(5, ?, ?, ?, ?, ?). 261scanlist(Pred, Xs, Ys, Zs, V1, V) :- foldl(Pred, Xs, Ys, Zs, V1, V).
262
263
264subseq(Sequence, [], Sequence).
265subseq([Head|Tail], [Head|SubTail], Complement) :-
266 subseq(Tail, SubTail, Complement).
267subseq([Head|Tail], SubSequence, [Head|Complement]) :-
268 subseq(Tail, SubSequence, Complement).
269
270
271subseq0(Sequence, SubSequence) :- subseq(Sequence, SubSequence, _).
272subseq1(Sequence, SubSequence) :-
273 subseq(Sequence, SubSequence, Complement),
274 Complement \== []
SICStus 4-compatible library(lists).