<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 10/10/2012 03:55 PM, Charles Hixson wrote:
<blockquote cite="mid:5075FCF2.6060502@earthlink.net" type="cite">I'm
choosing a language to implement a ... well, neural network is
wrong, and so is cellular automaton, but it gives the idea.
Anyway, I'm going to need, in each cell, a few stateful items,
e.g. activation level.
<br>
<br>
When I look at what Erlang can do, I see that the Process
Dictionary looks as if it would serve my needs, but then I am
immediately warned not to use it, that it will cause bugs. These
stateful terms will not be exported from the cell within which
they are resident. Is this still likely to cause problems? Is
there some better approach to maintaining state? (I can't just
generate a new process, because other cells will need to know how
to access this one, or to test that it has been rolled out.)
<br>
<br>
</blockquote>
<tt>This explains some basics about the process dictionary: </tt><a class="moz-txt-link-freetext" href="http://www.erlang.org/course/advanced.html#dict">http://www.erlang.org/course/advanced.html#dict</a><br>
Quoted below:<br>
<ul>
<li>Destroys referential transparency
</li>
<li>Makes debugging difficult
</li>
<li>Survives Catch/Throw</li>
</ul>
So, it is much better to use variables, so side-effects are more
explicit (i.e., function variables). This is the equivalent to the
State variable of a gen_server behaviour
(<a class="moz-txt-link-freetext" href="http://www.erlang.org/doc/man/gen_server.html">http://www.erlang.org/doc/man/gen_server.html</a>). Depending on the
expected state-handling, you might want a gen_server, a gen_event,
or a gen_fsm for each cell. Otherwise, if you want to avoid OTP
behaviour usage, you could just do plain Erlang code, but your code
might then be more error-prone (especially since you are asking this
question).<br>
<br>
</body>
</html>