bug in scoping for higher order terms

Lee Naish lee at cs.mu.OZ.AU
Mon Mar 8 15:01:25 AEDT 1999


Fergus Henderson <fjh at cs.mu.OZ.AU> writes:

> > that, in a function, `:-' is pronounced `where', and so "the thing
> > being defined" is always what's left of the `=', and everything right
> > of the `=' is scoped to the enclosing clause.

>This is much closer to my natural intuition.

If you look at Prolog, it has basically the same scope/quantifier
problem for aggregates.  Mercury avoids the problem with aggregates by
using solutions/2 which accepts a closure.  This just make the same
problem re-appear when creating closures.

The standard Prolog solution is to treat as quantified all variables
appearing in the first argument of setof.  Those in the second argument
are "global" by default (they can be explicitly quantified using '^'/2).
Of course the quantification/scoping is not done properly and its all not
quite logical.

Its cleaned up in NU-Prolog's solutions/3, which (properly) quantifies
and scopes all variables in the first argument.  Variables in the second
argument use the default NU-Prolog quantification rule (quantify if the
variable occurs uniquely in the clause).

How can this be used to suggest a solution to the problem in Mercury?
The term in the first argument of solutions/3 can be seen as the single
argument in the head of an anonymous predicate definition.  The second
argument corresponds to the clause body.  This suggests that variables
in the head of a clause in a closure should be quantified (the scope
being the clause defining the closure), whereas the rest should use the
default (Mercury) quantification.  I believe this agrees with the
proposed definition above.  Some appropriate *general* rule for how the
programmer should relate function and predicate definitions should be used
to define the scope for function closures.

	lee



More information about the developers mailing list