Question on "The Erlang Way"
Håkan Stenholm
hakan.stenholm@REDACTED
Sun May 19 00:40:24 CEST 2002
>> I am new to Erlang. Can someone help me to "think the Erlang way"
>> on the following (I am from the Lisp world):
>>
>> 1) I want to create a "global" to the application dict. Is this
>> best
>> done by spawning a process that manages the dict (like the number
>> analyser sample in the Book)? It seems that because of the
>> "assign once"
>> strategy, regular variables do not work (dict:store returns a new
>> Dict).
>Regular variables are also local to a single process. But process
>names aren't, so a named process (like the number analyser example)
>is probably the way to go.
You can either use "gen_server" to create a custom server process or if
you only need a key-value database you could also use "ets", ets tables
can be created as either local or global - global ones can be accessed
by any other process.
There is also the "put" and "get" operations (see the erlang module) to
use the process dictionary, this allows global variables in the scoop of
a single process.
Process dictionaries should for obvious reasons (obfuscating code
execution flow) only be used sparingly.
Mnesia can be used as a alternative to ets if proper database
transaction support is needed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 1262 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20020519/70380a7f/attachment.bin>
More information about the erlang-questions
mailing list