<div dir="ltr"><div><div>Hmm, fun wrapping could be the basis of hygienic-case parse transform. I'll have to see what the performance overhead of a fun wrap is like.<br><br></div>The example I gave is contrived and a bit weak I guess. In my most recent run-in with this issue there were a lot of bindings from the enclosing scope that were used, so breaking things out to top level functions would not always be a good option. Funs would be better, but add clutter and maybe runtime overhead. Compromises, compromises....<br>
<br></div><div>Cheers,<br></div>Dan.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 3, 2014 at 12:46 PM, Thomas Lindgren <span dir="ltr"><<a href="mailto:thomasl_erlang@yahoo.com" target="_blank">thomasl_erlang@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:10pt;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif"><div>
You could hide the bindings inside a fun.</div><div><br></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">
A = (fun() -> case ... end end)( ),</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">
B = (fun() -> case ... end end)( ),</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">
{A, B}.</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif"><br></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">
Though I agree with Ivan that refactoring might be a better idea in this case. </div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">
<br></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">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="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">
<br></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">(Binary patterns are a special case; _some_ repeated variables are be benign there.)</div>
<div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif"><br></div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">
Best,</div><div style="font-style:normal;font-size:13px;background-color:transparent;font-family:HelveticaNeue,'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif">Thomas</div><div 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><div class="h5"> <div dir="ltr"> <font face="Arial"> On Monday, March 3, 2014 5:59 PM, Daniel Goertzen <<a href="mailto:daniel.goertzen@gmail.com" target="_blank">daniel.goertzen@gmail.com</a>> wrote:<br> </font> </div>
</div></div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;margin-top:5px;padding-left:5px"> <div><div><div class="h5"><div><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></div></div><div class="">_______________________________________________<br>
erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank">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></div> </blockquote> </div> </div> </div> </div></div></blockquote></div><br></div>