[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Understanding GNU vs SWI differences
From: |
Daniel Diaz |
Subject: |
Re: Understanding GNU vs SWI differences |
Date: |
Fri, 10 Aug 2012 09:08:25 +0200 |
Hi Alberto,
when you press ; (semicolon) you ask the top-level to look for another
solution. Maybe such a solution exists (it is then computed and displayed by
the top-level) or maybe not (in that case the top-level informs the user about
the failure). GNU Prolog tries to avoid to propose a ; to the user if it knows
there is no remaining solution. This behavior as also been followed by SWI.
Both systems detects there is no more solution depending on its internal state
(in fact it checks if there remains at least one choice-point in its choice
stack). For this GNU Prolog uses a clause indexing mechanism based on the first
argument. For this reason it can detect that f(a,X) has only 2 solution (and
does not propose a ;) while it cannot for f(X,b). Anyway this is a "plus", the
answer is not wrong.
SWI has adopted the same principle and also avoids to propose a ; if it knows
there is no more solution. Simply its internal state is not the same as gprolog
thus both systems do not detect the same situations.
?- sub_atom(abc,X,Y,Z,c).
X = 2,
Y = 1,
Z = 0 ;
false.
You can see that SWI also answers 'false'.
While gprolog detects there is no more solution and does not propose a ;
| ?- sub_atom(abc,X,Y,Z,c).
X = 2
Y = 1
Z = 0
yes
Daniel
Le 7 août 2012 à 16:10, Alberto Simões a écrit :
> Hello
>
> I am sorry if this is a trivial issue, that is explained somewhere. If
> so, please point me in that direction.
> Nevertheless, when doing some experiments with SWI Prolog and GNU
> Prolog, I found out some different behavior on some simple things:
>
> This is my SWI Prolog run:
>
> ?- [user].
> |: f(a,b).
> |: f(c,d).
> |: f(a,d).
> |: % user://1 compiled 0.00 sec, 5 clauses
> true.
>
> ?- f(X,b).
> X = a.
>
> ?- f(a,X).
> X = b ;
> X = d.
>
> ?- f(X,d).
> X = c ;
> X = a.
>
> In fact, SWI Prolog never says true/false/yes/no. It just show the
> possible results.
>
> In GNU Prolog I get this:
>
> | ?- [user].
> compiling user for byte code...
> f(a,b).
> f(c,d).
> f(a,d).
>
> user compiled, 4 lines read - 331 bytes written, 9192 ms
>
> yes
> | ?- f(X,b).
>
> X = a ? ;
>
> no
> | ?- f(a,X).
>
> X = b ? ;
>
> X = d
>
> yes
> | ?- f(X,d).
>
> X = c ? ;
>
> X = a
>
> (1 ms) yes
>
> Although I can understand the 'yes' answer, I can't get why in the
> first iteration GNU Prolog stopped and gave me the chance to ask for
> more solutions (while in the next two it didn't). And, why did it say
> "no" (ok, it said no because it didn't find any other solution, but
> then, why did it try to get more solutions in that case?)
>
> Thank you
> Kindest regards,
> Alberto
>
> --
> Alberto Simões
>
> _______________________________________________
> Users-prolog mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/users-prolog
>
> --
> Ce message a ete verifie par MailScanner
> pour des virus ou des polluriels et rien de
> suspect n'a ete trouve.
>
--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.