An over enthusiastic warning ?
Richard A. O'Keefe
ok@REDACTED
Wed May 24 01:15:47 CEST 2006
Roger Price <rprice@REDACTED> wrote:
The following code was produced by a compiler [1] which replaced unused
variables U4 and U5 by wildcards,
fun ([_U4|_U5]) ->
fun ([_U4|_U5]) -> %% Warnings for wildcards _U4 and _U5
fun ([U4|U5]) ->
fun ([U6|U7]) -> {'C',U1,U4,U5,U6,U7}
end(U3)
end(U2)
end(U3)
end(U2)
Wrong. "_" is a wild-card, NOTHING ELSE is a wild-card.
but the Erlang (BEAM) emulator version 5.4.9 [source] [hipe] with Eshell
V5.4.9 issued warnings:
./test0.erl:25: Warning: variable '_U4' shadowed in 'fun'
./test0.erl:25: Warning: variable '_U5' shadowed in 'fun'
Erlang is helpful indeed to warn about this.
If you want wild-cards, generate
fun ([_|_]) ->
fun ([_|_]) ->
fun ([U4|U5]) ->
fun ([U6|U7]) -> {'C',U1,U4,U5,U6,U7}
end(U3)
end(U2)
end(U3)
end(U2)
Better yet, notice that "is U2 a pair" is being checked twice
and "is U3 a list" is being checked twice, and generate
fun([U4|U5]) -> fun ([U6|U7]) -> {'C',U1,U4,U5,U6,U7} end(U3) end(U2)
More information about the erlang-questions
mailing list