users-prolog
[Top][All Lists]
Advanced

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

Strange variables...


From: Fred Bapst
Subject: Strange variables...
Date: Thu, 08 Jan 2015 20:57:02 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

I'm observing a rather strange behaviour (GnuProlog 1.4.4 on Windows and Linux,
idem for older versions) and I'm not able to completely isolate it; it seems to
be related to singleton variables and backtracking. Here is a stupid code
demonstrating the issue:

%--------------
z(A,B, A,B).
z(A,B, B,A).

p5(Ls):-
    _ = [B, C],
    % write(B), % write(C),
    Ls = [A, E],
    z(A, _, 1, 2),
    E=3,
    z(A, _, B, C).

%--------------

Asking for every solution leads to an infinite loop...

  ?- p5(X).
  X = [1,3] ? a
     ...... [infinine loop].....

Writing B and C removes the problem; and writing only one of them leads to
another strange behavior.

Running the call with the tracer also changes the behavior, and reveals
strange d(...) sub-terms:

{trace}
| ?- p5(X).
      1    1  Call: p5(_23) ?
      2    2  Call: z(_53,_57,1,2) ?
      2    2  Exit: z(1,2,1,2) ?
      3    2  Call: z(1,_85,_126,_127) ?
      3    2  Exit: z(1,_85,1,_85) ?
      1    1  Exit: p5([1,3]) ?
X = [1,3] ? a
      1    1  Redo: p5([1,3]) ?
      3    2  Redo: z(1,_85,1,_85) ?
      3    2  Exit: z(1,_85,_85,1) ?
      1    1  Exit: p5([1,3]) ?
X = [1,3]
      1    1  Redo: p5([1,3]) ?
      2    2  Redo: z(1,2,1,2) ?
      2    2  Exit: z(2,1,1,2) ?
      3    2  Call:
z(2,_85,d(3,[a(z(2,_85,d(3,[a(z(2,_85,...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),2)
?
      3    2  Exit:
z(2,d(3,[a(z(2,d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),d(3,[a(z(2,d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),2)
?
      1    1  Exit: p5([2,3]) ?
X = [2,3]
(16 ms) yes
{trace}




reply via email to

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