YAP 7.1.0
List Predicates in the Prolog Library

More...

Detailed Description

List Manipulation Predicates


Class Documentation

◆ list_concat/2

class list_concat/2

list_concat(+ Lists,? List)

True when Lists is a list of lists and List is the concatenation of Lists

◆ max_list/2

class max_list/2

max_list(? Numbers, ? Max)

True when Numbers is a list of numbers, and Max is the maximum

◆ min_list/2

class min_list/2

min_list(? Numbers, ? Min)

True when Numbers is a list of numbers, and Min is the minimum

◆ nth/3

class nth/3

nth(? N, ? List, ? Elem)

The same as nth1/3

◆ nth/4

class nth/4

nth(? N, ? List, ? Elem, ? Rest)

Same as nth1/4

◆ nth0/3

class nth0/3

nth0(? N, ? List, ? Elem)

True when Elem is the Nth member of List, counting the first as element 0 (That is, throw away the first N elements and unify Elem with the next.) It can only be used to select a particular element given the list and index For that task it is more efficient than member/2

◆ nth0/4

class nth0/4

nth0(? N, ? List, ? Elem, ? Rest)

Unifies Elem with the Nth element of List, counting from 0, and Rest with the other elements It can be used to select the Nth element of List (yielding Elem and Rest), or to insert Elem before the Nth (counting from 1) element of Rest, when it yields List, e.g nth0(2, List, c, [a,b,d,e]) unifies List with [a,b,c,d,e] nth/4 is the same except that it counts from 1 nth0/4 can be used to insert Elem after the Nth element of Rest

◆ nth1/3

class nth1/3

nth1(+ Index,? List,? Elem)

nth1(? N, ? List, ? Elem)

Succeeds when the Index-th element of List unifies with Elem Counting starts at 1

Set environment variable Name and Value should be instantiated to atoms or integers The environment variable will be passed to shell/[0-2] and can be requested using getenv/2 They also influence expand_file_name/2

The same as nth0/3 , except that it counts from 1, that is nth(1, [H|_], H)

◆ nth1/4

class nth1/4

nth1(? N, ? List, ? Elem, ? Rest)

Unifies Elem with the Nth element of List, counting from 1, and Rest with the other elements It can be used to select the Nth element of List (yielding Elem and Rest), or to insert Elem before the Nth (counting from 1) element of Rest, when it yields List, e.g nth(3, List, c, [a,b,d,e]) unifies List with [a,b,c,d,e] nth/4 can be used to insert Elem after the Nth element of Rest

◆ numlist/3

class numlist/3

numlist(+ Low, + High, + List)

If Low and High are integers with Low =< High, unify List to a list [Low, Low+1, ...High] See also between/3

◆ permutation/2

class permutation/2

permutation(+ List,? Perm)

True when List and Perm are permutations of each other

◆ remove_duplicates/2

class remove_duplicates/2

remove_duplicates(+ List, ? Pruned)

Removes duplicated elements from List Beware: if the List has non-ground elements, the result may surprise you

◆ same_length/2

class same_length/2

same_length(? List1, ? List2)

True when List1 and List2 are both lists and have the same number of elements No relation between the values of their elements is implied Modes same_length(-,+) and same_length(+,-) generate either list given the other; mode same_length(-,-) generates two lists of the same length, in which case the arguments will be bound to lists of length 0, 1, 2, ...

◆ append/2

class append/2

append(? Lists,? Combined)

% % Concatenate a list of lists Is true if Lists is a list of % lists, and List is the concatenation of these lists % %

Parameters
ListOfListsmust be a list of -possibly- partial lists

◆ last/2

class last/2

last(+ List,? Last)

True when List is a list and Last is identical to its last element d(_, [X], L)

◆ selectchk/3

class selectchk/3

selectchk(? Element, ? List, ? Residue)

Semi-deterministic selection from a list Steadfast: defines as

selectchk(Elem, List, Residue) :-
select(Elem, List, Rest0), select,
Rest = Rest0.
select(? Element, ? List, ? Residue)
selectchk(? Element, ? List, ? Residue)

◆ select/3

class select/3

select(? Element, ? List, ? Residue)

True when Set is a list, Element occurs in List, and Residue is everything in List except Element (things stay in the same order)

◆ suffix/2

class suffix/2

suffix(? Suffix, ? List)

Holds when append(_,Suffix,List) holds

◆ sumlist/2

class sumlist/2

sumlist(? Numbers, ? Total)

True when Numbers is a list of integers, and Total is their sum The same as sum_list/2 , please do use sum_list/2 instead

◆ sum_list/3

class sum_list/3

sum_list(? Numbers, + SoFar, ? Total)

True when Numbers is a list of numbers, and Total is the sum of their total plus SoFar

◆ sum_list/2

class sum_list/2

sum_list(? Numbers, ? Total)

True when Numbers is a list of numbers, and Total is their sum

◆ flatten/2

class flatten/2

flatten(+ List, ? FlattenedList)

Flatten a list of lists List into a single list FlattenedList

?- flatten([[1],[2,3],[4,[5,6],7,8]],L).
L = [1,2,3,4,5,6,7,8] ? ;
flatten(+ List, ? FlattenedList)

◆ intersection/3

class intersection/3

intersection(+ Set1, + Set2, + Set3)

Succeeds if Set3 unifies with the intersection of Set1 and Set2 Set1 and Set2 are lists without duplicates They need not be ordered

The code was copied from SWI-Prolog's list library

◆ memberchk/2

class memberchk/2

memberchk(+ Element, + Set)

As member/2 , but may only be used to test whether a known Element occurs in a known Set In return for this limited use, it is more efficient when it is applicable

◆ member/2

class member/2

member(?Element, ?Set) is true when Set is a list, and Element occurs in it

It may be used to test for an element or to enumerate all the elements by backtracking Indeed, it may be used to generate the Set!

member(? Element, ? Set)

True when Set is a list, and Element occurs in it It may be used to test for an element or to enumerate all the elements by backtracking

◆ identical_member/2

class identical_member/2

identical_member(?Element, ?Set)

properties: nondeterministic

% identical_member holds true when Set is a list, and Element is exactly identical to one of the elements that occurs in it

◆ append/3

class append/3

append(? List1,? List2,? List3)

Succeeds when List3 unifies with the concatenation of List1 and List2 The predicate can be used with any instantiation pattern (even three variables)

◆ delete/3

class delete/3

delete(+ List, ? Element, ? Residue)

eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee True when List is a list, in which Element may or may not occur, and Residue is a copy of List with all elements identical to Element deleted

eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

◆ length/2

class length/2

length(? L,? S)

Unify the well-defined list L with its length The procedure can be used to find the length of a pre-defined list, or to build a list of length S