[erlang-questions] how to scale into the cloud using process? example computing simple average

Bengt Kleberg <>
Tue May 19 10:26:37 CEST 2009


The return value of spawn/1 is the (Erlang) process identity. If you
want data from a process you have to send it (using !) and receive it
(using receive).

It would be a good idea to read one of the Erlang books or the online


On Tue, 2009-05-19 at 01:55 -0600, Kid Erlang wrote:
> hi again everybody!  it has been a few months of using Erlang!  I have
> been porting my Perl scripts into Erlang and now I am almost done!!!
> thanks for your help before getting my scripts ported over.
> my program is now in Erlang except I do not see how to make it scale
> into the cloud.  I have heard I need to use Erlang process to do this
> but I do not understand how this is works.  I have tried using spawn
> command to create a processes but it does not seem to do anything.
> Where is good documentation for how to use spawn?
> I try to write simple example with spawn.  I want to make simple
> average of these numbers as example, but calculate in paralell so it
> can automagically scale into the cloud!  Here is my program:
> -module(averager).
> -compile(export_all).
> paralell_average(List)->
>   N=0,lists:foreach(fun(X)-> spawn(fun()-> N+X
> end)end,List),N/length(List).
> but it always returns 0.0 no mater what List is!  what am I doing
> wrong? :(  I have tried to use N+=X like in Perl but I think this does
> not work because of the single assignment?  same with N=N+X.  how can
> I make processes make the value of N go up?  I don't get it :(
> I have also read that processes must be in recursive?  How would I
> write this process in recursive?
> and as soon as my program is made of processes where is good
> documentation for making it scale into the cloud?
> - Kid Erlang 
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list