[m-dev.] Adding default clauses to the language.

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Aug 9 16:18:49 AEST 2001


On 09-Aug-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> On Thu, Aug 09, 2001 at 01:06:13AM +1000, Fergus Henderson wrote:
> > On 08-Aug-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> > > Similarly, one might shorten det_map2 to
> > > 
> > > det_map2(_, [],       []      ) = [].
> > > det_map2(F, [X | Xs], [Y | Ys]) = [F(X, Y) | det_map2(F, Xs, Ys)].
> > > 
> > > otherwise det_map2(_, _, _) = throw("inputs of different lengths").
> > 
> > I don't think you can define a declarative semantics for that
> > in a mode-independent fashion.
> > 
> > I am strongly opposed to the introduction of any syntactic
> > constructs whose declarative semantics depends on the modes.
> 
> Actually, I think there may be a mode-independent semantics, but Mercury
> probably can't fully implement it.  The semantics is what you get by taking
> the otherwise clause and adding the negations of all the other clauses.
> Take this example:
> 
> 	p(1,1,X) :- q(1,X).
> 	p(2,2,4).
> 	otherwise p(_, _, 6).
> 
> The semantics is:
> 
> 	p(1,1,X) :- q(1,X).
> 	p(2,2,4).
> 	p(A, B, C) :- \+(A=1,B=1,q(1,C)), \+(A=2,B=2,C=4), C=6.

That doesn't have the semantics that you want.

Consider the query ?- p(2, 2, 6).
According to the semantics you proposed, this query would succeed;
the first negation succeeds because A=1 fails (since A = 2),
the second negation succeeds because C=4 fails (since C = 6),
and the unification C = 6 succeeds.

So the query ?- p(2, 2, X) would have two solutions, X = 4 *and* X = 6.
That is not what you want.

You could probably give the version for functions a mode-independent declarative
semantics.  But I'm not sure this extension is worth it if it only works
for functions.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list