singleton variables in prolog

Singleton variables are useless in Prolog, and are easily introduced by editing typos.

The warning is welcome to me, as it allows to easily spot such frequent cause of error.

Being a warning, you can run code containing singletons, but any value these eventually will assume will be lost.

I don’t think that ISO standard (never heard about ANSI) forbids such variables.

You could rewrite your example in this way

member(X, [Y|T]) :- X = Y ; member(X, T).

and then forget about the singleton.

Leave a Comment