Quote:

> Hello,

> does anyone know how to compare 2 lists in prolog to find out if one

> list is part of the other ??

> I want to be able to find out if a short list (max. 16 Elements)

> equals with a part of a longer list (max. 64 Elements).

> For example I want to know if [a,b,c,d,e,f,g,h] includes [b,c,d,e].

> So I need something like the member/2 command comparing lists.

> Does anyone know if there is a command doing the job in SWI-prolog or

> how to write a function solving the problem ?

> I also need the position of the first element of the equal part. If

> anyone knows a solution for thar one, I'd be pleased to hear it, too.

> I appreciate any hint.

> Thanks,

> Mathias

The Edinburgh Public Domain Library contains a number of list processing

predicates including:

subseq0/2

get or check subsequences of a list

subseq0(Sequence, SubSequence)

+Sequence <list>

?SubSequence <list> or <variable>

subseq0(Sequence, SubSequence)

is true when SubSequence is a subsequence of Sequence, but may

be Sequence itself. Thus subseq0([a,b], [a,b]) is true as well

as subseq0([a,b], [a]).

Example

?- bagof(S, subseq0([a,b], S), B).

S = _ ,

B = [[a,b],[b],[],[a]]

________________________________________________________________________

subseq1/2

get or check proper subsequences of a list

subseq1(Sequence, SubSequence)

+Sequence <list>

?SubSequence <list> or <variable>

subseq1(Sequence, SubSequence)

is true when SubSequence is a proper subsequence of Sequence,

that is it contains at least one element less.

Example

?- bagof(S, subseq1([a,b], S), B).

S = _ ,

B = [[b],[],[a]]

The library is at http://www.ifs.org.uk/~popx/prolog/library.html

Richard