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

Peter Schachte schachte at cs.mu.OZ.AU
Wed Aug 8 22:39:02 AEST 2001


On Wed, Aug 08, 2001 at 03:48:53AM -0700, Ralph Becket wrote:

> Would it be a terrible thing to add the option of having
> default clauses to the language, so one might write
> 
> :- func f(string) = int.
> 
> f("foo") = 1.
> f("bar") = 2.
> f("baz") = 3.
> otherwise f(_) = throw(...).

I like it.

A few clarifications.  I assume the semantics is identical to the
if-then-else version?  What would it mean if I wrote:

	...
	otherwise f("zip") = throw(...).

I think you have to forbid anything but unique variables as head arguments
in an otherwise clause.  This would ensure that the otherwise clause would
always match.  But it could be useful to have non-anonymous head variables
in cases like:

	otherwise f(X) = throw(bad_value(X)).

I assume you would also allow:

	otherwise f(_) = 4.

(No reason the otherwise clause should have to throw an exception.)  I think
you probably want to limit it to one otherwise clause per function, and
require the otherwise clause to be last.

Otherwise clauses should be allowed for predicates as well.

Nice idea.

-- 
Peter Schachte                     In a democratic time culture, everyone's
mailto:schachte at cs.mu.OZ.AU        time is valueable and no one's time is
http://www.cs.mu.oz.au/~schachte/  any more expendable than another's.
Phone: +61 3 8344 9166                 -- Jeremy Rifkin 
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