[erlang-questions] I think I wish I could write case Any of whatever -> _ end.
Eric Newhuis (personal)
enewhuis@REDACTED
Mon May 17 17:21:04 CEST 2010
I am NOT proposing that the wild-card character behave selectively in pattern matching. That just isn't part of what I am proposing.
As far as I can tell, the wild-card is not presently allowed at all in the context that I have proposed. So there is no formal ambiguity as far as I can tell. And it wouldn't break any existing code. ...unless I am missing something basic.
I am not proposing that wild-card ('_') ever be reinterpreted on the left hand side of an arrow ('->').
To make this clearer one could introduce a special operator placeholder ('@').
>> 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.
On May 17, 2010, at 9:36 AM, Robert Virding wrote:
> 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