<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div>You could hide the bindings inside a fun.</div><div><br></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">   A = (fun() -> case ... end end)( ),</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">   B = (fun() -> case ... end end)( ),</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">   {A, B}.</div><div
 style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">Though I agree with Ivan that refactoring might be a better idea in this case. </div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">A related issue: I'd like to get warnings when variables are matched (not bound)
 in patterns. I've seldom found repeated variables very useful in practice, they can easily be rewritten to use explicit compares, and sometimes they have hidden groan-inducing bugs. </div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">(Binary patterns are a special case; _some_ repeated variables are be benign there.)</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue,
 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">Best,</div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">Thomas</div><div class="yahoo_quoted" style="display: block;"> <br> <br> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 10pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Monday, March 3, 2014 5:59 PM, Daniel Goertzen <daniel.goertzen@gmail.com> wrote:<br> </font> </div> <blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;">  <div class="y_msg_container"><div
 id="yiv4422137221"><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></div><br>_______________________________________________<br>erlang-questions mailing list<br><a ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br><br><br></div> </blockquote>  </div> </div>   </div> </div></body></html>