f1(X,Y)-><br>    case {X,Y} of<br>           {0, Q} -> {Q, Q} ;<br>           {P, Q} -> {P*Q, P+Q}<br>    end.<br><br>regards.<br><br>« Envoyé depuis mon mobile » Eric<br><br>Daniel Goertzen <daniel.goertzen@gmail.com> a écrit :<br><br><div dir="ltr"><div>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...<br><br>
f1(X, Y) -><br>    A = case {X,Y} of<br>            {0, Q} -> Q;<br>            {P, Q} -> P*Q<br>        end,<br><br>    B = case {X,Y} of<br>            {0, Q} -> Q;<br>            {P, Q} -> P+Q<br>        end,<br>
    {A,B}.<br><br><br></div><div>In situations like the above, I artificially change the variable names to avoid trouble and end up with something like this:<br><br>f1(X, Y) -><br>    A = case {X,Y} of<br>            {0, Q0} -> Q0;<br>
            {P0, Q0} -> P0*Q0<br>        end,<br><br>    B = case {X,Y} of<br>            {0, Q1} -> Q1;<br>            {P1, Q1} -> P1+Q1<br>        end,<br>    {A,B}.<br><br></div><div></div><div><br></div><div>
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?<br>
</div><div><br></div><div>I'd love to have a 'hygienic' case expression.  Could it be faked with parse transforms?<br><br></div><div>Dan.<br></div><br></div>