[erlang-questions] Inconsistent shadowing of variables in a fun

Robert Virding <>
Mon Jan 30 01:17:32 CET 2017


The shadowing warning is there because it is only there and list
comprehensions where variable in patterns are shadowed. No, it isn't
consistent but it follows how other functional languages do it, IIRC. The
problems with an evolving language.

Robert


On 30 January 2017 at 00:17, Richard A. O'Keefe <> wrote:

>
>
> On 30/01/17 11:06 AM, Robert Virding wrote:
>
>> When defining a fun the shadowing of variables occurring in arguments is
>> inconsistent.
>>
>> Why the difference? Shouldn't we be consistent in shadowing all variables?
>>
>
> I have always wished that Erlang did no shadowing at all.
>
> a(X) ->
>     case X+1 of X -> ooh ; _ -> ahh end.
>
> b(X) ->
>     (fun (X) -> ooh ; (_) -> ahh end)(X+1).
>
>
> 2> foo:a(0).
> ahh
> 3> foo:b(0).
> ooh
>
> Call *that* consistent?  I don't.
>
>
> 1> c(foo).
> foo.erl:8: Warning: this clause cannot match because a previous clause at
> line 8 always matches
> foo.erl:8: Warning: variable 'X' is unused
> foo.erl:8: Warning: variable 'X' shadowed in 'fun'
>
> That warning about 'X' being shadowed?
>
> LOVE IT LOVE IT LOVE IT!
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170130/fb448943/attachment.html>


More information about the erlang-questions mailing list