[erlang-questions] case expression scope
Eric Pailleau
eric.pailleau@REDACTED
Tue Mar 4 15:51:50 CET 2014
Hello,
in fact there is even no need to bind any other variable :
f1(X, Y) ->
case {X, Y} of
{0, Y} -> {Y, Y} ;
{X, Y} -> {X*Y, X+Y}
end.
and this can be reduced to test only X value as 0 or other value. No need to test Y.
Regard...
« Envoyé depuis mon mobile » Eric
Eric Pailleau <eric.pailleau@REDACTED> a écrit :
>f1(X,Y)->
> case {X,Y} of
> {0, Q} -> {Q, Q} ;
> {P, Q} -> {P*Q, P+Q}
> end.
>
>regards.
>
>« Envoyé depuis mon mobile » Eric
>
>Daniel Goertzen <daniel.goertzen@REDACTED> a écrit :
>
>>One thing that repeatedly bites me is the way variables bindings leak out
>>of case expressions. For example, the following code fails to even compile
>>because the Ps and Qs smack into each other...
>>
>>f1(X, Y) ->
>> A = case {X,Y} of
>> {0, Q} -> Q;
>> {P, Q} -> P*Q
>> end,
>>
>> B = case {X,Y} of
>> {0, Q} -> Q;
>> {P, Q} -> P+Q
>> end,
>> {A,B}.
>>
>>
>>In situations like the above, I artificially change the variable names to
>>avoid trouble and end up with something like this:
>>
>>f1(X, Y) ->
>> A = case {X,Y} of
>> {0, Q0} -> Q0;
>> {P0, Q0} -> P0*Q0
>> end,
>>
>> B = case {X,Y} of
>> {0, Q1} -> Q1;
>> {P1, Q1} -> P1+Q1
>> end,
>> {A,B}.
>>
>>
>>The binding leakages seems like nothing but hassles and headaches to me, so
>>my questions is, is there actually a reason why bindings need leak out of
>>case expressions? Is there a programming style that leverages this
>>feature? Is there a limitation in the emulator that forces it to be this
>>way?
>>
>>I'd love to have a 'hygienic' case expression. Could it be faked with
>>parse transforms?
>>
>>Dan.
>>
>>_______________________________________________
>>erlang-questions mailing list
>>erlang-questions@REDACTED
>>http://erlang.org/mailman/listinfo/erlang-questions
>
>_______________________________________________
>erlang-questions mailing list
>erlang-questions@REDACTED
>http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140304/479cf51c/attachment.htm>
More information about the erlang-questions
mailing list