users-prolog
[Top][All Lists]
Advanced

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

Re: Strange variables...


From: Salvador Pinto Abreu
Subject: Re: Strange variables...
Date: Thu, 8 Jan 2015 23:51:22 +0000

while not really a solution to your problem, a workaround is to use the 
compiler (ie. gplc) instead of consulting.
you don't get debugging but performance is way better.

21:13:32$ gplc -o xx xx.pl 
21:13:38$ ./xx 
GNU Prolog 1.4.4 (64 bits)
Compiled Aug 27 2014, 09:59:03 with gcc
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?- p5(X).

X = [1,3] ? a

X = [1,3]

X = [2,3]

X = [2,3]

yes
| ?- 


> On 08 Jan 2015, at 19h57, Fred Bapst <address@hidden> wrote:
> 
> 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}
> 
> 
> _______________________________________________
> Users-prolog mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/users-prolog




reply via email to

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