Shadowed head variable in fun
Ulf Wiger
etxuwig@REDACTED
Fri May 23 14:14:02 CEST 2003
The Char in the fun's function head is not the same as Char
in the surrounding scope (thus the warning). The simplest
way to amend your implementation is probably:
symbol(Char) when integer(Char) ->
fun([C|Rest]) when C == Char -> [{Rest,Char}];
(Other) -> []
end.
I haven't verified absense of typos in the above code, but
you probably get the idea.
/Uffe
On Fri, 23 May 2003, WILLIAMS Dominic wrote:
>Hello,
>
>How does one 'consume' a head variable in a fun?
>
>symbol(Char) when integer(Char) ->
> fun([Char|Rest]) -> [{Rest,Char}];
> (Other) -> []
> end.
>
>This compiles with a Warning: variable 'Char' shadowed in 'fun'.
>And doesn't do what I want...
>
>i.e.
>
>F = symbol($a),
>F("Hello").
>
>returns [{"ello",72}] (I want it to return []).
>
>Thanks for your help,
>
>Dominic.
>
--
Ulf Wiger, Senior Specialist,
/ / / Architecture & Design of Carrier-Class Software
/ / / Strategic Product & System Management
/ / / Ericsson AB, Connectivity and Control Nodes
More information about the erlang-questions
mailing list