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

Eric Newhuis (personal) enewhuis@REDACTED
Mon May 17 23:07:48 CEST 2010


I guess I like it.  As easy as this is, I guess it is a sort of programming idiom.

Although I loathe the introduction of temporary variables I think this suggestion is a good compromise.

The one area where it still breaks down is when stringing two of these together.  I'd have to use a different temporary variable name for each block of code.  There is no LET construct in Erlang.  :(


On May 17, 2010, at 11:09 AM, Robert Raschke wrote:

> What's wrong with these? So, your temp var is now called X instead of _ and
> you always know what you're looking at.
> 
> On Mon, May 17, 2010 at 3:00 PM, Eric Newhuis (personal) <enewhuis@REDACTED
>> wrote:
> 
>> 
>> case some_module:some_function(...) of
>>       {some, pattern} -> _;
>>       {some, other, pattern} -> _;
>>       _ -> whatever
>> end.
>> 
>> 
> case X = some_module:some_function(...) of
>       {some, pattern} -> X;
>       {some, other, pattern} -> X;
>       _ -> whatever
> end.
> 
> 
> case some_module:some_function(...) of
>>       {some, pattern} ->
>>               {encapsulated, _};
>>       {some, other, pattern} ->
>>               {another, _, encapsulation}
>> end.
>> 
>> 
> case X = some_module:some_function(...) of
>       {some, pattern} ->
>               {encapsulated, X};
>       {some, other, pattern} ->
>               {another, X, encapsulation}
> end.
> 
> 
> 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.
>> 
>> 
> case some_module:some_function(...) of
>       {some, X, pattern} -> % _1
>               case X of ->  % _2
>                       {some, great, pattern} ->
>                               not_so_bad;
>                       _ -> % _3
>                               {_, Kind, _} = X, % _4, _5, _6
>                               Kind
>               end
> end.
> 
> 
> Robby



More information about the erlang-questions mailing list