[erlang-questions] Re: Correct syntax of a case clause

Bryan Fink bryan.fink@REDACTED
Mon Jun 15 17:41:43 CEST 2009


On Mon, Jun 15, 2009 at 9:49 AM, mats cronqvist<masse@REDACTED> wrote:
> Sean Cribbs <seancribbs@REDACTED> writes:
>
>> If you have only a,b,c as possible matches, I'd do it like this:
>>
>> case Expr of
>>  c -> block2;
>>  _ -> block1
>> end
>
>  this has the huge disadvantage of breaking when you add 'd' to the
>  possible values of Expr.

Hi, Mats.  I'm struck by how many interpretations this statement can
have when assumptions about context are altered.  I think rewording
your statement illustrates the alternate assumptions I'm thinking of:

"this has the huge disadvantage of *not* breaking when you add 'd' to
the possible values of Expr."

"this has the huge *advantage* of *not* breaking when you add 'd' to
the possible values of Expr."

Each of these rewordings takes issue with the fact that the case
clause doesn't fail when Expr='d'; it matches, and block1 is
evaluated.  The statements differ with each other over whether this is
intended behavior.  Just a reconsideration of what "breaking" means in
context (function failure or interface nonconformance).

It's similar to how one (probably) wouldn't write a list-reverse that
only worked on lists with only integer elements, but one might add a
clause to it that did something special for elements that were
themselves lists (thus implementing deep-reverse, for example).  With
such a list-reverse in hand, it may be desired either that later
language changes that add new types to the language cause the function
to fail (to remind implementers to check special cases) or that such
language additions do not cause the function to fail (because it
really should operate the same on any element that is not a list).

-Bryan


More information about the erlang-questions mailing list