[erlang-questions] Why does this happen?

Michael McDaniel <>
Sun Jun 3 05:07:35 CEST 2007


 Works fine on my system

 $ uname -a
 Linux delora 2.6.20-15-386 #2 Sun Apr 15 07:34:00 UTC 2007 i686 GNU/Linux

 eshell V5.5.3 (R11B-4)


:~/misc/src/erlang$ erl
Erlang (BEAM) emulator version 5.5.3 [async-threads:0] [hipe] [kernel-poll:false]

=> reading /home/mmcdanie/.erlang
=> ** Found 0 name clashes in code paths
Eshell V5.5.3  (abort with ^G)
1> f().
ok
2> X=[1,2,3,4].
[1,2,3,4]
3> 
3> Y=fun(Z)->Z*Z end.
#Fun<erl_eval.6.56006484>
4> Y(2).
4
5> Y(4).
16
6> import(lists).
ok
7> lists:map(Y,X).
[1,4,9,16]
8> f().
ok
9> lists:map(Y,X).
** 1: variable 'Y' is unbound **
10> X=[1,2,3,4].      
[1,2,3,4]
11> Y=fun(Z)->Z*Z end.
#Fun<erl_eval.6.56006484>
12> lists:map(Y,X).
[1,4,9,16]


~M

On Sun, Jun 03, 2007 at 02:41:39AM +0000, Brent McConnell wrote:
> 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?
> 
> 8> f().
> ok
> 9> X=[1,2,3,4].
> [1,2,3,4]
> 10> Y=fun(Z)->Z*Z end.
> #Fun<erl_eval.6.56006484>
> 11> Y(2).
> 4
> 12> Y(4).
> 16
> 13> import (lists).
> ok
> 14> lists:map(Y,X).
> [1,4,9,16]
> 15> f().
> ok
> 16> import (lists).
> ok
> 17> X=[1,2,3,4].
> [1,2,3,4]
> 18> Y=fun(Z)->Z*Z end.
> 
> =ERROR REPORT==== 3-Jun-2007::02:31:08 ===
> 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-'...
> 
> ** exited: {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-',3}]} **
> 19>
> 
> !DSPAM:52,46622c3918341335313201!

> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> !DSPAM:52,46622c3918341335313201!


-- 
Michael McDaniel
Portland, Oregon, USA
http://autosys.us
+1 503 283 5284



More information about the erlang-questions mailing list