[erlang-questions] Bound(?) var in anonymous fun
Pablo Vieytes
pablo.vb80@REDACTED
Tue Dec 18 11:54:53 CET 2012
I want to delete an item from a list and I've written this fun.
delete_key_from_list(Key, StatusList)->
lists:foldr(
fun(Key, Acc) ->
Acc;
(Another, Acc) ->
[Another|Acc]
end,
[],
StatusList).
src/file.erl:172: Warning: variable 'Key' is unused
src/file.erl:174: Warning: variable 'Key' is unused
src/file.erl:174: Warning: variable 'Key' shadowed in 'fun'
src/file.erl:176: Warning: this clause cannot match because a previous
clause at line 174 always matches
I guessed Key was bound so I could use for pattern matching. It's very easy
to fix it but I don't know why it doesn't work.
Fixed version:
delete_key_from_list(Key, StatusList)->
lists:foldr(
fun(K, Acc) when K == Key ->
Acc;
(Another, Acc) ->
[Another|Acc]
end,
[],
StatusList).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121218/aaeaa75f/attachment.htm>
More information about the erlang-questions
mailing list