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

Mark Brown dougl at cs.mu.OZ.AU
Thu Aug 9 10:51:59 AEST 2001


On 08-Aug-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> The following is a fairly common idiom in Mercury:
> 
> :- func f(string) = int.
> 
> f(S) = ( if f_2(S) = X then X else throw(...) ).
> 
> :- func f_2(string) = int is semidet.
> 
> f_2("foo") = 1.
> f_2("bar") = 2.
> f_3("baz") = 3.
> 
> 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 would oppose this idea; (wearing my purist hat) I am highly suspicious
of the fact that a single syntactic entity, a clause, does not have any
well-defined meaning of its own, but depends on the other clauses for
its interpretation.  In general it would not be possible to verify the
correctness of an 'otherwise' clause without first looking at other
clauses for the predicate or function.  In my view, this would be a
great loss.

Furthermore (and this is with the purist hat off), you have not
convinced me that there is any great advantage in allowing default
clauses.  I like if-then-elses.   I believe that, despite some attempts
to the contrary, they *can* be formatted in a legible way.  The only
advantage that I can see for using a default clause is that it would
require fewer levels of indentation, but I think there are better ways
of achieving this -- namely, introducing additional predicates/functions.

So at this stage I am very far from being convinced that this proposal
is acceptable.

Cheers,
Mark.

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