root/tags/lgt291/library/listp.lgt

Revision 2, 4.6 KB (checked in by pmoura, 7 years ago)

Initial revision

  • 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.0,
7        authors is 'Paulo Moura',
8        date is 2000/7/24,
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(nth/3).
121
122    :- mode(nth(?integer, +list, ?term), zero_or_more).
123
124    :- info(nth/3, [
125        comment is 'Nth element of a list.',
126        argnames is ['Nth', 'List', 'Element']]).
127
128
129    :- public(permutation/2).
130
131    :- mode(permutation(?list, ?list), zero_or_more).
132
133    :- info(permutation/2,
134        [comment is 'The two lists are a permutation of the same list.',
135         argnames is ['List', 'Permutation']]).
136
137
138    :- public(prefix/2).
139
140    :- mode(prefix(?list, +list), zero_or_more).
141
142    :- info(prefix/2,
143        [comment is 'Prefix is a prefix of List.',
144         argnames is ['Prefix', 'List']]).
145
146
147    :- public(reverse/2).
148
149    :- mode(reverse(+list, ?list), zero_or_one).
150    :- mode(reverse(?list, +list), zero_or_one).
151    :- mode(reverse(-list, -list), one_or_more).
152
153    :- info(reverse/2,
154        [comment is 'Reverses a list.',
155         argnames is ['List', 'Reversed']]).
156
157
158    :- public(same_length/2).
159
160    :- mode(same_length(+list, ?list), zero_or_one).
161    :- mode(same_length(?list, +list), zero_or_one).
162    :- mode(same_length(-list, -list), one_or_more).
163
164    :- info(same_length/2,
165        [comment is 'The two lists have the same length.',
166         argnames is ['List1', 'List2']]).
167
168
169    :- public(select/3).
170
171    :- mode(select(?term, +list, ?list), zero_or_more).
172    :- mode(select(?term, ?list, +list), zero_or_more).
173
174    :- info(select/3,
175        [comment is 'Selects an element from a list, returning the list of remaining elements.',
176         argnames is ['Element', 'List', 'Remaining']]).
177
178
179    :- public(sort/2).
180
181    :- mode(sort(+list, -list), one).
182
183    :- info(sort/2,
184        [comment is 'Sorts a list in ascending order.',
185         argnames is ['List', 'Sorted']]).
186
187
188    :- public(sublist/2).
189
190    :- mode(sublist(?list, +list), zero_or_more).
191
192    :- info(sublist/2,
193        [comment is 'The first list is a sublist of the second.',
194         argnames is ['Sublist', 'List']]).
195
196
197    :- public(subtract/3).
198
199    :- mode(subtract(+list, +list, -list), one).
200
201    :- info(subtract/3,
202        [comment is 'Removes all elements in the second list from the first list, returning the list of remaining elements.',
203         argnames is ['List', 'Elements', 'Remaining']]).
204
205
206    :- public(suffix/2).
207
208    :- mode(suffix(?list, +list), zero_or_more).
209
210    :- info(suffix/2,
211        [comment is 'Suffix is a suffix of List.',
212         argnames is ['Suffix', 'List']]).
213
214
215:- end_protocol.
Note: See TracBrowser for help on using the browser.