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

Peter Schachte schachte at cs.mu.OZ.AU
Thu Aug 9 13:38:30 AEST 2001


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.

Mercury can only implement this in modes (in, in, ?) (or similar).  But maybe
that's good enough:  if there are other modes, Mercury can give a "not
implemented" error message, or maybe a "we'll never implement this, you need
a CLP language for that" error message.

-- 
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