Discussion:
notational question about :Goal
Ross Boylan
2014-08-25 20:05:30 UTC
Permalink
The manual defines
findall(+Template, :Goal, -Bag)
and the "Notation of predicate descriptions"
(http://www.swi-prolog.org/pldoc/man?section=preddesc), say ":"
indicates a meta-argument.

What's a meta-argument? There is a reference to the discussion of
chapter 6 on modules, which includes 6.4 on meta-predicates, but that
seems to be something different.

I'm wondering about this because I was wondering if I could construct
a composite goal, perhaps like
(mount(A, B, W1), mount(A, B, W2), W1\= W2).
I realize that could be turned into a helper predicate.

I also notice the description of setof is
setof(+Template, +Goal, -Set)
for which Goal gets a "+" rather than a ":". I know there are
differences in how setof and findall work, but I'm not sure what to
make of the distinction--probably because I don't know what ":" means!

Thanks.
Ross Boylan
Richard A. O'Keefe
2014-08-25 22:23:02 UTC
Permalink
Post by Ross Boylan
The manual defines
findall(+Template, :Goal, -Bag)
and the "Notation of predicate descriptions"
(http://www.swi-prolog.org/pldoc/man?section=preddesc), say ":"
indicates a meta-argument.
What's a meta-argument?
An argument that represents something to do.
The convention always was that : represented
something that WASN'T a goal but needed module
annotation, while 0, 1, 2, .... represented a
a goal that was missing the rightmost n arguments.

SWI Prolog documentation appears to use :Goal
for an argument that is a complete callable term.
Post by Ross Boylan
I'm wondering about this because I was wondering if I could construct
a composite goal, perhaps like
(mount(A, B, W1), mount(A, B, W2), W1\= W2).
Yes, certainly.
Post by Ross Boylan
I realize that could be turned into a helper predicate.
For findall/3, it's just a style issue.

For setof/3 and bagof/3, you have to think
about the rĂ´les the variables play.
If a variable
- will be ground when findall, setof, or bagof is called
=> no worries
- is captured in the Template
=> no worries
- is local to your 'composite goal'
=> it must be explicitly existentially quantified
- is a wildcard
=> it is local to your 'composite goal' and cannot be
existentially quantified so you mustn't do that.

Let's suppose for argument's sake that in your example,
A will be ground, B is captured by the template, and W1
W2 are local to the composite goal. Then either you
should existentially quantify them
W1^W2^(mount(A, B, W1), mount(A, B, W2), W1 \== W2)
or you should introduce an auxiliary predicate
has_dual_mount(A, B)
where
has_dual_mount(A, B) :-
mount(A, B, W1), mount(A, B, W2), W1 \== W2.
Post by Ross Boylan
I also notice the description of setof is
setof(+Template, +Goal, -Set)
for which Goal gets a "+" rather than a ":".
Since bagof/3 in the same page uses :, I think you
can take it that this is an incomplete edit of the
documentation, not a subtle difference.

Loading...