[erlang-questions] *current* value?

David King <>
Wed Oct 17 20:34:33 CEST 2007


>> Most of the time there is some sort of main loop where the code is  
>> executed. The input data to the > loop function
>> is the place to use as storage for any data you need to keep.
> I'm not sure if I follow.  Are you saying that the variable within  
> the main loop can be accessed directly from the worker function  
> without being passed in?

No, he's saying that usually you write programs like this:

main_loop(State) ->
   receive
       {eat_cookies,Cookies} ->
         NewState=eat_cookies(State,Cookies);
       {bake_cookies} ->
         NewState=bake_cookies(State)
     end,
   main_loop(NewState).

So that all of the state is encased in the arguments, rather than  
putting some in the process dictionary.



More information about the erlang-questions mailing list