[erlang-questions] I think I wish I could write case Any of whatever -> _ end.

Robert Virding rvirding@REDACTED
Mon May 17 16:36:54 CEST 2010


On 17 May 2010 16:00, Eric Newhuis (personal) <enewhuis@REDACTED> wrote:
> ...
>
> I guess where readability might break down is in nesting:
>
> case some_module:some_function(...) of
>        {some, _, pattern} -> % _1
>                case _ of ->  % _2
>                        {some, great, pattern} ->
>                                not_so_bad;
>                        _ -> % _3
>                                {_, Kind, _} = _, % _4, _5, _6
>                                Kind
>                end
> end.
>
> Although I can still read the above once I learn that underscore ('_') is context sensitive.
>
> _1 :: any()
> _2 :: {some, any(), pattern}
> _3 :: {some, any(), pattern}, not {some, great, pattern}
> _4 :: some
> _5 :: pattern
> _6 :: _3

That is completely "unworkable". To put it very mildly. To have '_' in
a pattern sometimes be a don't care which matches anything and is
dropped and sometimes be a value which is matched against is just not
acceptable. To make it even worse it changes its value in the body
which would be the only case where this happens. Also the usage in
your 4,5,6 case is inconsistent with the other examples as Pat = Expr
is really just a shorter form of:

case Expr of
    Pat -> <rest of clause>
end

and completely equivalent to it except for the error message. So you really have

case _ of
    {_,Kind,_} -> Kind
end

which doesn't behave as you imply.

Sorry no!

Robert


More information about the erlang-questions mailing list