Re: Singleton variable in branch: right warning message?
Parker Jones <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Thank you for the explanation, Michael. It makes sense now. > Date: Mon, 17 Mar 2014 08:43:07 -0600 > From: [email protected] > To: [email protected] > CC: [email protected] > Subject: Re: [SWIPL] Singleton variable in branch: right warning message? > > 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 > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog -------------- next part -------------- HTML attachment scrubbed and removed