'singleton variable in branch’ warning

278 views
Skip to first unread message

Kuniaki Mukai

unread,
Dec 10, 2016, 6:18:46 AM12/10/16
to <swi-prolog@googlegroups.com>
Hi,

I got a 'singleton variable in branch’ warning,
which, I think, is not.

An simplified reproduction is this:

% swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 7.3.32-50-g7e3ea373b)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- [user].
singleton_variable_in_branch(X, Y):-
|: (X=X0 -> true
|: ; ( Y=Y0-> ( true -> X0=Y0) )
|: ).

Warning: user://1:8:
Singleton variable in branch: X0
|: true.

?-

Kuniaki Mukai

Feliks Kluzniak

unread,
Dec 10, 2016, 6:32:01 AM12/10/16
to Kuniaki Mukai, <swi-prolog@googlegroups.com>
Hi,

It seems to me X0 has two occurrences, and each of them is a singleton.

This is easier to see if one rewrites

head :- body1 ; body2 .

to the logically equivalent

head :- body1.
head :- body2.

Am I missing something?

— Feliks
> --
> You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Kuniaki Mukai

unread,
Dec 10, 2016, 6:50:30 AM12/10/16
to Feliks Kluzniak, <swi-prolog@googlegroups.com>

> On 2016 Dec 10, at 20:31, Feliks Kluzniak <feliks....@telia.com> wrote:
>
> Hi,
>
> It seems to me X0 has two occurrences, and each of them is a singleton.
>
> This is easier to see if one rewrites
>
> head :- body1 ; body2 .
>
> to the logically equivalent
>
> head :- body1.
> head :- body2.
>
> Am I missing something?

You are right. In fact, the warning tells me a bug,
difficult to debug: X0 was a typo of X in my actual codes.
Thanks.

Kuniaki Mukai
Reply all
Reply to author
Forward
0 new messages