Re: Singleton variable in branch: right warning message?

Michael Hendricks <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAFHuXub9COcP6hDxE6_P6hfOJ3YLSgDVrgt7m9VgmeGort=bng@mail.gmail.com>
On Mon, Mar 17, 2014 at 6:32 AM, Parker Jones <[email protected]> wrote:

> This code gives the warning "Singleton variable in branch: A", but
> shouldn't it be a regular singleton warning?
>
>
> p(X) :-
>     (X > 0 ->
>         A=1
>         ;
>         A=0
>     ).


It's not a regular singleton warning because the variable A appears twice
in this clause.  This code has two branches: X > 0 and X =< 0.  Simplifying
you have roughly:

P(X) :- A=1. % when X > 0
P(X) :- A=0. % when X =< 0

You can see that A is a singleton (appears only once) in each of those
clauses (each representing a branch).

By adding write(A), you add a second occurrence of the variable A to each
branch, so it's no longer a singleton.

-- 
Michael
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.