1

I'm using some code from the Art of Prolog. This example is causing an error in GNU Prolog.

mem(X,[X|Xs]).
user:2: warning: singleton variables [Xs] for mem/2
mem(X,[Y|Ys]) :- mem(X,Ys).
user:3: warning: singleton variables [Y] for mem/2

Now I test a query, with negative results:

| ?- mem(g, [a, g, e]).
uncaught exception: error(existence_error(procedure,mem/2),top_level/0)

The example from the book:

enter image description here

It appears a singleton is a variable that is used only once in the expression. To fix the warning:

mem(X, [X|_]).
mem(X, [_|Ys]) :- mem(X, Ys).


| ?- mem(b, [a, b, c]).
true

| ?- mem(d, [a, b, c]).

no

Why does the second expression not return false? Also, why the differences from the Art of Prolog and GNU Prolog? Did something change in the standard?

notaorb
  • 1,944
  • 1
  • 8
  • 18
  • See https://stackoverflow.com/questions/15416220/singleton-variables-in-prolog – brebs Aug 02 '23 at 22:58
  • That example has a bug in the code. I eliminated the singleton error, but still get unexpected results. I was expecting false in the last example. Also, did the standards change since publication of this book? – notaorb Aug 03 '23 at 00:09
  • "No" is the "False" you expect. There is not such a thing as a _standard_ Prolog. All implementations differ slightly here and there, and adhere to a published standard to some degree (some are very close to the standard and others do differently on purpose). – TA_intern Aug 03 '23 at 09:33
  • 2
    false and no can be considered equivalent. In SWI prolog, for example, you get false, but other prolog systems may adopt different conventions – damianodamiano Aug 03 '23 at 09:36

0 Answers0