| 1 | |
|---|
| 2 | :- protocol(listp). |
|---|
| 3 | |
|---|
| 4 | :- info([ |
|---|
| 5 | version is 1.2, |
|---|
| 6 | author is 'Paulo Moura', |
|---|
| 7 | date is 2004/5/9, |
|---|
| 8 | comment is 'List protocol.']). |
|---|
| 9 | |
|---|
| 10 | :- public(append/3). |
|---|
| 11 | :- mode(append(?list, ?list, ?list), zero_or_more). |
|---|
| 12 | :- info(append/3, [ |
|---|
| 13 | comment is 'Appends two lists.', |
|---|
| 14 | argnames is ['List1', 'List2', 'List']]). |
|---|
| 15 | |
|---|
| 16 | :- public(delete/3). |
|---|
| 17 | :- mode(delete(@list, @term, ?list), one). |
|---|
| 18 | :- info(delete/3, |
|---|
| 19 | [comment is 'Deletes from a list all ocurrences of an element returning the list of remaining elements.', |
|---|
| 20 | argnames is ['List', 'Element', 'Remaining']]). |
|---|
| 21 | |
|---|
| 22 | :- public(delete_matches/3). |
|---|
| 23 | :- mode(delete_matches(@list, @term, ?list), one). |
|---|
| 24 | :- info(delete_matches/3, |
|---|
| 25 | [comment is 'Deletes all matching elements from a list, returning the list of remaining elements.', |
|---|
| 26 | argnames is ['List', 'Element', 'Remaining']]). |
|---|
| 27 | |
|---|
| 28 | :- public(empty/1). |
|---|
| 29 | :- mode(empty(@list), zero_or_one). |
|---|
| 30 | :- info(empty/1, |
|---|
| 31 | [comment is 'True if the argument is an empty list.', |
|---|
| 32 | argnames is ['List']]). |
|---|
| 33 | |
|---|
| 34 | :- public(flatten/2). |
|---|
| 35 | :- mode(flatten(+list, -list), one). |
|---|
| 36 | :- info(flatten/2, |
|---|
| 37 | [comment is 'Flattens a list of lists into a list.', |
|---|
| 38 | argnames is ['List', 'Flatted']]). |
|---|
| 39 | |
|---|
| 40 | :- public(keysort/2). |
|---|
| 41 | :- mode(keysort(+list, -list), one). |
|---|
| 42 | :- info(keysort/2, |
|---|
| 43 | [comment is 'Sorts a list of key-value pairs in ascending order.', |
|---|
| 44 | argnames is ['List', 'Sorted']]). |
|---|
| 45 | |
|---|
| 46 | :- public(last/2). |
|---|
| 47 | :- mode(last(?list, ?term), zero_or_more). |
|---|
| 48 | :- info(last/2, |
|---|
| 49 | [comment is 'List last element (if it exists).', |
|---|
| 50 | argnames is ['List', 'Last']]). |
|---|
| 51 | |
|---|
| 52 | :- public(length/2). |
|---|
| 53 | :- mode(length(?list, ?integer), zero_or_more). |
|---|
| 54 | :- info(length/2, |
|---|
| 55 | [comment is 'List length.', |
|---|
| 56 | argnames is ['List', 'Length']]). |
|---|
| 57 | |
|---|
| 58 | :- public(max/2). |
|---|
| 59 | :- mode(max(+list, -term), zero_or_one). |
|---|
| 60 | :- info(max/2, |
|---|
| 61 | [comment is 'Determines the list maximum value using standard order. Fails if the list is empty.', |
|---|
| 62 | argnames is ['List', 'Maximum']]). |
|---|
| 63 | |
|---|
| 64 | :- public(member/2). |
|---|
| 65 | :- mode(member(?term, ?list), zero_or_more). |
|---|
| 66 | :- info(member/2, |
|---|
| 67 | [comment is 'Element is a list member.', |
|---|
| 68 | argnames is ['Element', 'List']]). |
|---|
| 69 | |
|---|
| 70 | :- public(memberchk/2). |
|---|
| 71 | :- mode(memberchk(?term, ?list), zero_or_one). |
|---|
| 72 | :- info(memberchk/2, |
|---|
| 73 | [comment is 'Checks if a term is a member of a list.', |
|---|
| 74 | argnames is ['Element', 'List']]). |
|---|
| 75 | |
|---|
| 76 | :- public(min/2). |
|---|
| 77 | :- mode(min(+list, -term), zero_or_one). |
|---|
| 78 | :- info(min/2, |
|---|
| 79 | [comment is 'Determines the minimum value in a list using standard order. Fails if the list is empty.', |
|---|
| 80 | argnames is ['List', 'Minimum']]). |
|---|
| 81 | |
|---|
| 82 | :- public(nextto/3). |
|---|
| 83 | :- mode(nextto(?term, ?term, ?list), zero_or_more). |
|---|
| 84 | :- info(nextto/3, [ |
|---|
| 85 | comment is 'X and Y are consecutive elements in List.', |
|---|
| 86 | argnames is ['X', 'Y', 'List']]). |
|---|
| 87 | |
|---|
| 88 | :- public(nth0/3). |
|---|
| 89 | :- mode(nth0(?integer, ?list, ?term), zero_or_more). |
|---|
| 90 | :- info(nth0/3, [ |
|---|
| 91 | comment is 'Nth element of a list (counting from zero).', |
|---|
| 92 | argnames is ['Nth', 'List', 'Element']]). |
|---|
| 93 | |
|---|
| 94 | :- public(nth0/4). |
|---|
| 95 | :- mode(nth0(?integer, ?list, ?term, ?list), zero_or_more). |
|---|
| 96 | :- info(nth0/4, [ |
|---|
| 97 | comment is 'Nth element of a list (counting from zero).', |
|---|
| 98 | argnames is ['Nth', 'List', 'Element', 'Residue']]). |
|---|
| 99 | |
|---|
| 100 | :- public(nth1/3). |
|---|
| 101 | :- mode(nth1(?integer, ?list, ?term), zero_or_more). |
|---|
| 102 | :- info(nth1/3, [ |
|---|
| 103 | comment is 'Nth element of a list (counting from one).', |
|---|
| 104 | argnames is ['Nth', 'List', 'Element']]). |
|---|
| 105 | |
|---|
| 106 | :- public(nth1/4). |
|---|
| 107 | :- mode(nth1(?integer, ?list, ?term, ?list), zero_or_more). |
|---|
| 108 | :- info(nth1/4, [ |
|---|
| 109 | comment is 'Nth element of a list (counting from zero).', |
|---|
| 110 | argnames is ['Nth', 'List', 'Element', 'Residue']]). |
|---|
| 111 | |
|---|
| 112 | :- public(permutation/2). |
|---|
| 113 | :- mode(permutation(?list, ?list), zero_or_more). |
|---|
| 114 | :- info(permutation/2, |
|---|
| 115 | [comment is 'The two lists are a permutation of the same list.', |
|---|
| 116 | argnames is ['List', 'Permutation']]). |
|---|
| 117 | |
|---|
| 118 | :- public(prefix/2). |
|---|
| 119 | :- mode(prefix(?list, +list), zero_or_more). |
|---|
| 120 | :- info(prefix/2, |
|---|
| 121 | [comment is 'Prefix is a prefix of List.', |
|---|
| 122 | argnames is ['Prefix', 'List']]). |
|---|
| 123 | |
|---|
| 124 | :- public(reverse/2). |
|---|
| 125 | :- mode(reverse(+list, ?list), zero_or_one). |
|---|
| 126 | :- mode(reverse(?list, +list), zero_or_one). |
|---|
| 127 | :- mode(reverse(-list, -list), one_or_more). |
|---|
| 128 | :- info(reverse/2, |
|---|
| 129 | [comment is 'Reverses a list.', |
|---|
| 130 | argnames is ['List', 'Reversed']]). |
|---|
| 131 | |
|---|
| 132 | :- public(same_length/2). |
|---|
| 133 | :- mode(same_length(+list, ?list), zero_or_one). |
|---|
| 134 | :- mode(same_length(?list, +list), zero_or_one). |
|---|
| 135 | :- mode(same_length(-list, -list), one_or_more). |
|---|
| 136 | :- info(same_length/2, |
|---|
| 137 | [comment is 'The two lists have the same length.', |
|---|
| 138 | argnames is ['List1', 'List2']]). |
|---|
| 139 | |
|---|
| 140 | :- public(select/3). |
|---|
| 141 | :- mode(select(?term, +list, ?list), zero_or_more). |
|---|
| 142 | :- mode(select(?term, ?list, +list), zero_or_more). |
|---|
| 143 | :- info(select/3, |
|---|
| 144 | [comment is 'Selects an element from a list, returning the list of remaining elements.', |
|---|
| 145 | argnames is ['Element', 'List', 'Remaining']]). |
|---|
| 146 | |
|---|
| 147 | :- public(sort/2). |
|---|
| 148 | :- mode(sort(+list, -list), one). |
|---|
| 149 | :- info(sort/2, |
|---|
| 150 | [comment is 'Sorts a list in ascending order.', |
|---|
| 151 | argnames is ['List', 'Sorted']]). |
|---|
| 152 | |
|---|
| 153 | :- public(sublist/2). |
|---|
| 154 | :- mode(sublist(?list, +list), zero_or_more). |
|---|
| 155 | :- info(sublist/2, |
|---|
| 156 | [comment is 'The first list is a sublist of the second.', |
|---|
| 157 | argnames is ['Sublist', 'List']]). |
|---|
| 158 | |
|---|
| 159 | :- public(subtract/3). |
|---|
| 160 | :- mode(subtract(+list, +list, -list), one). |
|---|
| 161 | :- info(subtract/3, |
|---|
| 162 | [comment is 'Removes all elements in the second list from the first list, returning the list of remaining elements.', |
|---|
| 163 | argnames is ['List', 'Elements', 'Remaining']]). |
|---|
| 164 | |
|---|
| 165 | :- public(suffix/2). |
|---|
| 166 | :- mode(suffix(?list, +list), zero_or_more). |
|---|
| 167 | :- info(suffix/2, |
|---|
| 168 | [comment is 'Suffix is a suffix of List.', |
|---|
| 169 | argnames is ['Suffix', 'List']]). |
|---|
| 170 | |
|---|
| 171 | :- end_protocol. |
|---|