I am new to Erlang and have been playing in the shell. I have some behavior that seems odd when importing the lists module and wanted to ask a more knowledgeable audience why it does this. In the first few lines I define a list and a function, import lists and then map the function. I then clear variables and start again but this time I import lists before defining the function and it fails. Why?
<br><br>8> f().<br>ok<br>9> X=[1,2,3,4].<br>[1,2,3,4]<br>10> <span style="font-weight: bold;">Y=fun(Z)->Z*Z end.</span><br>#Fun<erl_eval.6.56006484><br>11> Y(2).<br>4<br>12> Y(4).<br>16<br>13> import (lists).
<br>ok<br>14> lists:map(Y,X).<br>[1,4,9,16]<br>15> f().<br>ok<br>16> import (lists).<br>ok<br>17> X=[1,2,3,4].<br>[1,2,3,4]<br>18> <span style="font-weight: bold;">Y=fun(Z)->Z*Z end.</span><br><br>=ERROR REPORT==== 3-Jun-2007::02:31:08 ===
<br>Error in process <0.45.0> with exit value: {badarg,[{erlang,atom_to_list,[{module,lists}]},{erl_lint,'-unused_vars/3-fun-0-',2},{orddict,filter,2},{orddict,filter,2},{erl_lint,unused_vars,3},{erl_lint,check_unused_vars,3},{erl_lint,fun_clause,3},{erl_lint,'-fun_clauses/3-fun-0-'...
<br><br>** exited: {badarg,[{erlang,atom_to_list,[{module,lists}]},<br> {erl_lint,'-unused_vars/3-fun-0-',2},<br> {orddict,filter,2},<br> {orddict,filter,2},
<br> {erl_lint,unused_vars,3},<br> {erl_lint,check_unused_vars,3},<br> {erl_lint,fun_clause,3},<br> {erl_lint,'-fun_clauses/3-fun-0-',3}]} **
<br>19> <br><br>