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

Peter Schachte schachte at cs.mu.OZ.AU
Thu Aug 9 16:34:42 AEST 2001


On Thu, Aug 09, 2001 at 04:18:49PM +1000, Fergus Henderson wrote:
> > 	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.
...
> So the query ?- p(2, 2, X) would have two solutions, X = 4 *and* X = 6.
> That is not what you want.

Yikes, you're right.  I guess you'd need some way in the non-otherwise
clauses to indicate which parts of the clause the otherwise clause assumes
have failed and which it doesn't.  Kind of a guard.  Yuck.  Hey, we could
use "!" as the guard operator! :-b

Alright, I guess this just isn't going to work.  Bummer.

> You could probably give the version for functions a mode-independent declarative
> semantics.

I wouldn't think so.  Aren't functions the same as predicates, aside from
syntax and a default mode?  Wouldn't 

f(1, 1) = q(1).
f(2, 2) = 4.
otherwise f(_, _) = 6.

have the same problem?

> But I'm not sure this extension is worth it if it only works
> for functions.

Agreed.

-- 
Peter Schachte                     Brook's Law: Adding manpower to a late
mailto:schachte at cs.mu.OZ.AU        software project makes it later 
http://www.cs.mu.oz.au/~schachte/  
Phone: +61 3 8344 9166             
PGP key available, see web page    
--------------------------------------------------------------------------
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