Error reported when using pmap

Michael McDaniel <>
Wed Aug 30 17:54:05 CEST 2006


 $ uname -a
 Linux delora 2.6.15-23-386 #1 PREEMPT Tue May 23 13:49:40 UTC 2006 i686 GNU/Linux
 $ cat testmain.erl
 -module(testmain).
 -export([test3/0]).

 test3() ->
     MyList = [1,2,3,4,5,6,7,8,9,10],
     lists:map(fun(I) -> I*2 end, MyList).

 $ erl -sname del
 Erlang (BEAM) emulator version 5.5 [source] [async-threads:0] [hipe]

 Eshell V5.5  (abort with ^G)
 ()1> c(testmain).
 {ok,testmain}
 ()2> testmain:test3().
 [2,4,6,8,10,12,14,16,18,20]
 ()3> l(testmain).
 {module,testmain}
 ()4>


~M


On Wed, Aug 30, 2006 at 04:22:28PM +0800, Arbow wrote:
> Hi All:
>       I am new in Erlang, and try the pmap at http://www.erlang.org/ml-archive/
> erlang-questions/200606/msg00187.html:
> 
> In file test.erl:
> -module(test).
> -export([pmap/2]).
> 
> pmap(F, L) ->
>     S = self(),
>     Pids = list:map(
>                     fun(I) ->
>                         spawn(
>                               fun() ->
>                                   do_f(S, F, I)
>                               end)
>                     end, L),
>     gather(Pids).
> 
> gather([H|T]) ->
>     receive
>         {H, Ret} -> [Ret|gather(T)]
>     end;
> gather([]) ->
>     [].
> 
> do_f(Parent, F, I) ->
>     io:format("Receive item ~w~n", [I]),
>     Parent ! {self(), (catch F(I))}.
> 
> In file testmain.erl:
> -module(testmain).
> -export([test3/0]).
> 
> test3() ->
>     MyList = [1,2,3,4,5,6,7,8,9,10],
>     lists:map(fun(I) -> I*2 end, MyList).
> 
> when I execute " testmain:test3(). ", I get errors:
> 
> =ERROR REPORT==== 30-Aug-2006::16:21:51 ===
> Error in process <0.36.0> on node '' with exit value:
> {undef,[{testmain,test3,[]},{erl_eval,do_apply,5},{shell,exprs,6},
> {shell,eval_loop,3}]}
> 
> ** exited: {undef,[{testmain,test3,[]},
>                    {erl_eval,do_apply,5},
>                    {shell,exprs,6},
>                    {shell,eval_loop,3}]} **
> 
> Anyone could help me? Thanks.
> 
> Best regards.
> Arbow

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



More information about the erlang-questions mailing list