sys_pre_expand compiler warning (Re: Algorithmic lists)
Robert Virding
rv@REDACTED
Tue Oct 17 11:03:46 CEST 2000
Ulf Wiger <etxuwig@REDACTED> writes:
>On Mon, 16 Oct 2000, Ulf Wiger wrote:
>
>>
>>Here's my first (and perhaps last) hack of sys_pre_expand.erl.
>>It handles at least my very simple test function with a list
>>comprehension that is fed a lazy list:
>
>BTW, when I compiled sys_pre_expand.erl, I got the following compiler
>warning:
>
>> erlc -W sys_pre_expand.erl
>/home/etxuwig/work/erlang/lazy/sys_pre_expand.erl:703: Warning:
>variable 'Es' shadowed in 'fun'
>
>The function in question looks like this:
>
>bin_expand_strings(Es0) ->
> foldr(fun ({bin_element,Line,{string,_,S},default,default}, Es) ->
> foldr(fun (C, Es) ->
>
>[{bin_element,Line,{integer,Line,C},default,default}|Es]
> end, Es, S);
> (E, Es) -> [E|Es]
> end, [], Es0).
>
>
>Now, it doesn't really seem like a bug, but wouldn't it be awfully
>easy to avoid the warning and resulting confusion? ;)
The reason that there is a warning here (and in funs when head
variables shadow) is that this is a departure from standard Erlang
practice of NOT shadowing. For example in
X = ...,
case ... of
{a,X} ->
the X in the pattern inside the case does not shadow the outer X.
(Which is contrary to most other functional languages) It was felt
that it would be better to highlight this to avoid confusion.
Otherwise people might expect that a head variable in a fun should
match if it already bound.
I agree it is sometimes irretating when I KNOW what I am doing (which
of course I always do :-), but this is in keeping with the philosophy o
ftrying to keep things simple, consistent and easy to learn so we
highlight inconsistencies.
Robert
--
Robert Virding Tel: +46 (0)8 545 55 017
Alteon Web Systems Email: rv@REDACTED
S:t Eriksgatan 44 WWW: http://www.bluetail.com/~rv
SE-112 34 Stockholm, SWEDEN
"Folk säger att jag inte bryr mig om någonting, men det skiter jag i".
More information about the erlang-questions
mailing list