This package defines operations on lists. Lists are a very basic data structure, but nevertheless certain very frequent operations are provided in this package.
To load the package, enter the query
| ?- use_module(library(lists)).
append(?Prefix, ?Suffix, ?Combined)delete(+List, +Element, ?Residue)is_list(+List)last(?List, ?Last)
| ?- last([x,y,z], Z).
Z = z
max_list(+ListOfNumbers, ?Max)member(?Element, ?List) | ?- member(X, [a,b,c]).
X = a ? ;
X = b ? ;
X = c ? <RET>
yes
memberchk(+Element, +List)memberchk/2 only
succeeds once and can therefore not be used to enumerate the elements in
List. Example:
| ?- memberchk(X, [a,b,c]).
X = a ? ;
no
min_list(+ListOfNumbers, ?Min)nextto(?X, ?Y, ?List) | ?- nextto(X, Y, [1,2,3]).
X = 1,
Y = 2 ? ;
X = 2,
Y = 3 ? ;
no
no_doubles(?List)dif(X, Y) holds for all pairs of members X and
Y of the list.
non_member(?Element, ?List)dif(Element, Y) holds for all members Y of the
list.
nth(?N, ?List, ?Element) | ?- nth(N, [a,b,c,d,e,f,g,h,i], f).
N = 6
nth(?N, ?List, ?Element, ?Rest)nth0(?N, ?List, ?Element)nth0(?N, ?List, ?Element, ?Rest) | ?- nth0(N, [a,b,c,d,e,f,g,h,i,j], f, R).
N = 5,
R = [a,b,c,d,e,g,h,i,j]
permutation(?List, ?Perm)prefix(?Prefix, ?List) | ?- prefix([1,2,3], [1,2,3,4,5,6]).
remove_duplicates(+List, ?Pruned) | ?- remove_duplicates([1,2,3,2,3,1], P).
P = [1,2,3] ? ;
no
reverse(?List, ?Reversed)same_length(?List1, ?List2)same_length(?List1, ?List2, ?Length) | ?- same_length([1,2,3], [9,8,7], N).
N = 3 ? ;
no
select(?Element, ?List, ?List2)sublist(?Sub, ?List)substitute(+X, +Xlist, +Y, ?Ylist) | ?- substitute(1, [1,2,3,4], 5, X).
X = [5,2,3,4]
sum_list(+ListOfNumbers, ?Sum)suffix(?Suffix, ?List)