Re: How to get a set response interactively

Ross Boylan <[email protected]> Wed, 09 Apr 2014 16:52:39 -0700
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <1397087559.15810.73.camel@localhost>
On Thu, 2014-04-10 at 11:24 +1200, Richard A. O'Keefe wrote:
> On 9/04/2014, at 1:16 PM, Ross Boylan wrote:
> 
> > I tried 
> > ?- setof(OS, mount(_, path([OS | _]), _W), Mounts).
> 
> Right there I see an obvious problem:  you have a wild-card
> in the generator.  More than one, in fact.
> 
> If you have a 'don't-care' variable in a generator,
> you MUST explicitly existentially quantify it.  And
> this requires having at least two occurrences of the
> variable: where it's needed and also in the quantifier.
> 
> This has absolutely nothing to do with interactive use
> of setof/3.  What you need to write is
> 
> ?- setof(OS, U^V^W^mount(U, path([OS|V]), W), Mounts).
> 
Thanks.  That works like a charm.
I thought from the manual it was supposed to be something with a + since
the manual says
"The construct +Var^Goal tells bagof/3 not to bind Var in Goal. bagof/3
fails if Goal has no solutions."

Taking + to be a meta-notation doesn't seem to fit either, since in that
role it usually means ground.

I must say I don't understand why setof and findall behave differently.

> Better still, create an auxiliary predicate:
> 
> mount_os(OS) :-
>     mount(_, path([OS|_]), _).
> 
> and then call
> 
> ?- setof(OS, mount_os(OS), Mounts).
> 
> 
> Jan, SWI Prolog has made so many changes lately to make life
> easier for some programmers; is there any chance of making it
> complain loudly about single-occurrence variables in setof/3
> or bagof/3 generators?
I doubt that would have helped me.
Ross
> 
>