<div>From my understanding, the N in this case can never be an unbound variable. If you rename N to M, then it won't compile, so it would not be possible for it to shadow anything.</div><div><br></div><div>It is similar to map keys. They are always treated as values, even when inside patterns.</div><div><br></div><div><br><div class="gmail_quote"><div>On Sun, Jan 29, 2017 at 23:07 Robert Virding <<a href="mailto:rvirding@gmail.com">rvirding@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">When defining a fun the shadowing of variables occurring in arguments is inconsistent. So with<br class="gmail_msg"><br class="gmail_msg"></div><span style="font-family:monospace,monospace" class="gmail_msg">a(X, N) -><br class="gmail_msg"></span></div><span style="font-family:monospace,monospace" class="gmail_msg"> fun (<<X,Y:N,_/binary>>) -> {X,Y} end.</span><br class="gmail_msg"><br class="gmail_msg"></div>the X in the fun arguments shadows the X from before it while the N is imported and used. An example:<br class="gmail_msg"><br class="gmail_msg"><span style="font-family:monospace,monospace" class="gmail_msg">1> c(bt).<br class="gmail_msg">bt.erl:8: Warning: variable 'X' is unused<br class="gmail_msg">bt.erl:9: Warning: variable 'X' shadowed in 'fun'<br class="gmail_msg">{ok,bt}<br class="gmail_msg">2> f(G),G=bt:a(34,8).<br class="gmail_msg">#Fun<bt.1.1070726><br class="gmail_msg">3> G(<<1,2,3,4,5>>). <br class="gmail_msg">{1,2}<br class="gmail_msg">4> f(G),G=bt:a(34,16).<br class="gmail_msg">#Fun<bt.1.1070726><br class="gmail_msg">5> G(<<1,2,3,4,5>>). <br class="gmail_msg">{1,515}</span><br class="gmail_msg"><br class="gmail_msg">Why the difference? Shouldn't we be consistent in shadowing all variables?<br class="gmail_msg"><br class="gmail_msg"></div>Robert<br class="gmail_msg"><br class="gmail_msg"></div>
_______________________________________________<br class="gmail_msg">
erlang-questions mailing list<br class="gmail_msg">
<a href="mailto:erlang-questions@erlang.org" class="gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="gmail_msg">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="gmail_msg" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="gmail_msg">
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div><div><br></div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Director of R&D</span></div></span></div></span></div></div></div></div>