[ ECLiPSe Lists Library predicate.|Group Index|
Full Index]
subset(?SubList, +List)
Succeeds if List is the list which contains all elements from SubList in
the same order as in SubList.
- ?SubList
- A term which unifies with a list.
- +List
- A term which unifies with a list.
Description
Used to test if a specified list contains all elements of another list,
or to generate all sublists of a given list.
The definition of this Prolog library predicate is:
subset([],[]).
subset([X|L],[X|S]) :-
subset(L,S).
subset(L, [_|S]) :-
subset(L,S).
The following should be noted;
1. This predicate does not perform any type testing functions.
2. This predicate is not protected by ECLiPSe and may be redefined without
generating a warning message.
3. This predicate works properly for set operations only, so repeated
elements, variable elements and unsorted lists should not be used.
Fail Conditions
Fails if SubList does not unify with a list whose elements are all
contained in List in the same order as in SubList.
Resatisfiable
Yes.
Exceptions
Examples
Success:
subset([1,3], [1,2,3]).
subset(X, [1,3,4]). % backtracks over all subsets
Fail:
subset([2,1], [1,2,3]). % different order
See Also
union / 3, subtract / 3, intersection / 3