bug-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sublist/2 recognizes subsequences as sublists


From: Heiko
Subject: sublist/2 recognizes subsequences as sublists
Date: Sat, 07 Jul 2012 01:28:04 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1

Hello Daniel,

thanks for your work!

I think I have found a bug.

At least the sublist/2 predicate does not what i would expect.
I get the effect of an subsequence instead of a sublist.

I also consulted the manual, which lapidarly states
List processing

sublist(List1, List2) succeeds if List1 is a sub-list of List2. This predicate is re-executable on backtracking.

So what is a sub-list?

GNU Prolog 1.4.1
By Daniel Diaz
Copyright (C) 1999-2012 Daniel Diaz
| ?- sublist([ll,r],[ll,l,rr,r]).

true ?

yes
| ?- sublist([l,r],[ll,l,rr,r]).

true ?

yes
| ?- sublist([rr,r],[ll,l,rr,r]).

true ?

yes
| ?-

I would consider only the result from the last call
"sublist([rr,r],[ll,l,rr,r])." correct,
since the first argument is a true sublist here.
The others calls should give a 'no' result, since there are
other elements ([l,rr] and [rr]) inserted.

I experimented with other sublist definitions also.
This definition of a sublist/2 predicate

sublist(S,L):-append(_,S,P),append(P,_,L).

from here
http://kti.mff.cuni.cz/~bartak/prolog.old/learning/LearningProlog2.html
exhausts all stack when the S argument is not a sublist of L (instead of 'no').

The following definition however works as expected:

sublist3(S,L):-prefix(S,L).
sublist3(S,[_|T]):-sublist3(S,T).

The expectation is that the calls with first two argument settings
should yield 'no' and the last should yield 'yes'.

My machine:
Windows XP SP3, AMD Athlon 2GHz, 3 GB RAM

I am using the MSVC-precompiled binary of GNU Prolog version 1.4.1 from the gnuprolog website.

Thanks for your attention and greetings,
Heiko EiƟfeldt




reply via email to

[Prev in Thread] Current Thread [Next in Thread]