[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: I think I have found a bug in list processing
From: |
Paulo Moura |
Subject: |
Re: I think I have found a bug in list processing |
Date: |
Fri, 30 Mar 2012 16:12:44 +0100 |
On 29/03/2012, at 16:24, phi16 wrote:
> I think the following dialogue is a bug:
>
>
> | ?- member(3,X),member(2,X),member(3,X).
>
> X = [3,2|_] ? ;
>
> X = [3,2,3|_] ? ;
>
> X = [3|_] ? ;
>
> X = [3,3|_] ? ;
>
> X = [3,_,3|_] ? ;
>
> X = [3,_,_,3|_] ? ;
>
> X = [3,_,_,_,3|_] ?
>
>
> The input tells the list named X must contain 2.
> But the 3rd output shows there is possible that X does not contain 2.
You're correct. It's a bug. The first call to member/2 constructs an open list
with 3 in the first position. The second call to member/2 adds 2 at the second
position. The third call to member/2 (the one you are backtracking to until you
will eventually run out of memory) will add 3 to the third position and, on
backtracking to the fourth, fifth, ... positions. I.e. the expected/correct
behavior is:
?- member(3,X),member(2,X),member(3,X).
X = [3,2|_A] ? ;
X = [3,2,3|_A] ? ;
X = [3,2,_A,3|_B] ? ;
X = [3,2,_A,_B,3|_C] ? ;
X = [3,2,_A,_B,_C,3|_D] ? ;
X = [3,2,_A,_B,_C,_D,3|_E] ? ;
X = [3,2,_A,_B,_C,_D,_E,3|_F] ? ;
X = [3,2,_A,_B,_C,_D,_E,_F,3|_G] ? ;
X = [3,2,_A,_B,_C,_D,_E,_F,_G,3|_H] ? ;
...
Cheers,
Paulo
-----------------------------------------------------------------
Paulo Jorge Lopes de Moura, PhD
Assistant Professor
Dep. of Computer Science, University of Beira Interior
6201-001 Covilhã, Portugal
Office 3.18 Ext. 3276
Phone: +351 275 242081 Fax: +351 275 319899
Email: <mailto:address@hidden>
Home page: <http://www.di.ubi.pt/~pmoura>
Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/>
-----------------------------------------------------------------