<div dir="ltr"><div>Would
it provide a solution
to just assume that the variable shadowing is never wanted?</div><div><br></div><div>What if code like:<br></div><div> f(X) -> fun(X) -> X end.</div><div> g(Y) -> case h() of Y -> %code% end.<br></div><div><br></div><div>1. Could create an error due to X being shadowed.</div><div>2. Could compile with inner X shadowed but a guard is added by the Erlang compiler, comparing inner to the outer:</div><div> f(X) -> fun(X2) when X2 =:= X -> X2 end.</div><div> g(Y) -> case h() of Y2 when Y2 =:= Y -> %code% end.</div><div></div>3. Current behaviour: Inner X is shadowed and is an entirely new variable (leads to naming and scoping confusion)<div><br></div><div>Solution 2 does not introduce new syntax and matches expectations for many developers. The compiler fixes the confusion during the compile time. Also should not break the existing code.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 27 Apr 2022 at 21:11, Attila Rajmund Nohl <<a href="mailto:attila.r.nohl@gmail.com">attila.r.nohl@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Fred Dushin <<a href="mailto:fred@dushin.net" target="_blank">fred@dushin.net</a>> ezt írta (időpont: 2022. ápr. 27., Sze, 15:14):<br>
><br>
[...]<br>
> But as noted later in the EEP, this can be written as<br>
><br>
> f(X, Y) -><br>
> F = fun ({a, Z}) when Z =:= Y -> {ok, Y};<br>
> (_) -> error<br>
> end,<br>
> F(X).<br>
[...]<br>
> And not to be too critical, but I am having a hard time understanding parts of the Rationale section. The author(s) suggest(s) that in current Erlang temporary variables are needed to achieve the same as the proposed glyph, but then provide an example that uses a guard (as above) but doesn't use a temporary variable, after all (?)<br>
<br>
Z is the temporary variable in the above example.<br>
<br>
> I am not sure what the problem is with temporary variables. The compiler has registers at its disposal, so I don't think it's a performance argument, but more an issue of readability, which again, I think is a purely aesthetic question, and has no bearing on the features of the language, per se. In other words, the proposal is not suggesting anything that cannot already be achieved in current Erlang, with effectively the same compiled BEAM ASM.<br>
<br>
Naming is hard, and if you have to come up with two meaningful<br>
variable names instead of one, it's even harder. This leads to code<br>
like this:<br>
<br>
F = fun ({a, TmpMeaningfulName}) when TmpMeaningfulName =:=<br>
MeaningfulName -> {ok, MeaningfulName};<br>
<br>
The current solution in the language easily leads to too long lines or<br>
overly verbose code.<br>
</blockquote></div>