root/tags/lgt2210/library/listp.lgt

Revision 943, 5.5 KB (checked in by pmoura, 5 years ago)

Removed predicate nth/3. Added predicates nth1/3, nth1/4, nth0/3, and nth0/4.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- protocol(listp).
3
4
5    :- info([
6        version is 1.2,
7        author is 'Paulo Moura',
8        date is 2004/5/9,
9        comment is 'List protocol.']).
10
11
12    :- public(append/3).
13
14    :- mode(append(?list, ?list, ?list), zero_or_more).
15
16    :- info(append/3, [
17        comment is 'Appends two lists.',
18        argnames is ['List1', 'List2', 'List']]).
19
20
21    :- public(delete/3).
22
23    :- mode(delete(@list, @term, ?list), one).
24
25    :- info(delete/3,
26        [comment is 'Deletes from a list all ocurrences of an element returning the list of remaining elements.',
27         argnames is ['List', 'Element', 'Remaining']]).
28
29
30    :- public(delete_matches/3).
31
32    :- mode(delete_matches(@list, @term, ?list), one).
33
34    :- info(delete_matches/3,
35        [comment is 'Deletes all matching elements from a list, returning the list of remaining elements.',
36         argnames is ['List', 'Element', 'Remaining']]).
37
38
39    :- public(empty/1).
40
41    :- mode(empty(@list), zero_or_one).
42
43    :- info(empty/1,
44        [comment is 'True if the argument is an empty list.',
45         argnames is ['List']]).
46
47
48    :- public(flatten/2).
49
50    :- mode(flatten(+list, -list), one).
51
52    :- info(flatten/2,
53        [comment is 'Flattens a list of lists into a list.',
54         argnames is ['List', 'Flatted']]).
55
56
57    :- public(keysort/2).
58
59    :- mode(keysort(+list, -list), one).
60
61    :- info(keysort/2,
62        [comment is 'Sorts a list of key-value pairs in ascending order.',
63         argnames is ['List', 'Sorted']]).
64
65
66    :- public(last/2).
67
68    :- mode(last(?list, ?term), zero_or_more).
69
70    :- info(last/2,
71        [comment is 'List last element (if it exists).',
72         argnames is ['List', 'Last']]).
73
74
75    :- public(length/2).
76
77    :- mode(length(?list, ?integer), zero_or_more).
78
79    :- info(length/2,
80        [comment is 'List length.',
81         argnames is ['List', 'Length']]).
82
83
84    :- public(max/2).
85
86    :- mode(max(+list, -term), zero_or_one).
87
88    :- info(max/2,
89        [comment is 'Determines the list maximum value using standard order. Fails if the list is empty.',
90         argnames is ['List', 'Maximum']]).
91
92
93    :- public(member/2).
94
95    :- mode(member(?term, ?list), zero_or_more).
96
97    :- info(member/2,
98        [comment is 'Element is a list member.',
99         argnames is ['Element', 'List']]).
100
101
102    :- public(memberchk/2).
103
104    :- mode(memberchk(?term, ?list), zero_or_one).
105
106    :- info(memberchk/2,
107        [comment is 'Checks if a term is a member of a list.',
108         argnames is ['Element', 'List']]).
109
110
111    :- public(min/2).
112
113    :- mode(min(+list, -term), zero_or_one).
114
115    :- info(min/2,
116        [comment is 'Determines the minimum value in a list using standard order. Fails if the list is empty.',
117         argnames is ['List', 'Minimum']]).
118
119
120    :- public(nextto/3).
121
122    :- mode(nextto(?term, ?term, ?list), zero_or_more).
123
124    :- info(nextto/3, [
125        comment is 'X and Y are consecutive elements in List.',
126        argnames is ['X', 'Y', 'List']]).
127
128
129    :- public(nth0/3).
130
131    :- mode(nth0(?integer, ?list, ?term), zero_or_more).
132
133    :- info(nth0/3, [
134        comment is 'Nth element of a list (counting from zero).',
135        argnames is ['Nth', 'List', 'Element']]).
136
137
138    :- public(nth0/4).
139
140    :- mode(nth0(?integer, ?list, ?term, ?list), zero_or_more).
141
142    :- info(nth0/4, [
143        comment is 'Nth element of a list (counting from zero).',
144        argnames is ['Nth', 'List', 'Element', 'Residue']]).
145
146
147    :- public(nth1/3).
148
149    :- mode(nth1(?integer, ?list, ?term), zero_or_more).
150
151    :- info(nth1/3, [
152        comment is 'Nth element of a list (counting from one).',
153        argnames is ['Nth', 'List', 'Element']]).
154
155
156    :- public(nth1/4).
157
158    :- mode(nth1(?integer, ?list, ?term, ?list), zero_or_more).
159
160    :- info(nth1/4, [
161        comment is 'Nth element of a list (counting from zero).',
162        argnames is ['Nth', 'List', 'Element', 'Residue']]).
163
164
165    :- public(permutation/2).
166
167    :- mode(permutation(?list, ?list), zero_or_more).
168
169    :- info(permutation/2,
170        [comment is 'The two lists are a permutation of the same list.',
171         argnames is ['List', 'Permutation']]).
172
173
174    :- public(prefix/2).
175
176    :- mode(prefix(?list, +list), zero_or_more).
177
178    :- info(prefix/2,
179        [comment is 'Prefix is a prefix of List.',
180         argnames is ['Prefix', 'List']]).
181
182
183    :- public(reverse/2).
184
185    :- mode(reverse(+list, ?list), zero_or_one).
186    :- mode(reverse(?list, +list), zero_or_one).
187    :- mode(reverse(-list, -list), one_or_more).
188
189    :- info(reverse/2,
190        [comment is 'Reverses a list.',
191         argnames is ['List', 'Reversed']]).
192
193
194    :- public(same_length/2).
195
196    :- mode(same_length(+list, ?list), zero_or_one).
197    :- mode(same_length(?list, +list), zero_or_one).
198    :- mode(same_length(-list, -list), one_or_more).
199
200    :- info(same_length/2,
201        [comment is 'The two lists have the same length.',
202         argnames is ['List1', 'List2']]).
203
204
205    :- public(select/3).
206
207    :- mode(select(?term, +list, ?list), zero_or_more).
208    :- mode(select(?term, ?list, +list), zero_or_more).
209
210    :- info(select/3,
211        [comment is 'Selects an element from a list, returning the list of remaining elements.',
212         argnames is ['Element', 'List', 'Remaining']]).
213
214
215    :- public(sort/2).
216
217    :- mode(sort(+list, -list), one).
218
219    :- info(sort/2,
220        [comment is 'Sorts a list in ascending order.',
221         argnames is ['List', 'Sorted']]).
222
223
224    :- public(sublist/2).
225
226    :- mode(sublist(?list, +list), zero_or_more).
227
228    :- info(sublist/2,
229        [comment is 'The first list is a sublist of the second.',
230         argnames is ['Sublist', 'List']]).
231
232
233    :- public(subtract/3).
234
235    :- mode(subtract(+list, +list, -list), one).
236
237    :- info(subtract/3,
238        [comment is 'Removes all elements in the second list from the first list, returning the list of remaining elements.',
239         argnames is ['List', 'Elements', 'Remaining']]).
240
241
242    :- public(suffix/2).
243
244    :- mode(suffix(?list, +list), zero_or_more).
245
246    :- info(suffix/2,
247        [comment is 'Suffix is a suffix of List.',
248         argnames is ['Suffix', 'List']]).
249
250
251:- end_protocol.
Note: See TracBrowser for help on using the browser.