

Brian's Functional Brain - edw519
http://blog.bestinclass.dk/index.php/2009/10/brians-functional-brain/

======
Tichy
"But we're doing this functionally, so we need to walk over the entire board,
apply the rules and return an entire board."

This is why I am still wary of adopting these languages with "fixed memory".
Ok for a cellular automaton there happened to be a workaround, but in general,
isn't all data connected somehow? So how does one handle that in a big system
with lot's of data? I can not change ALL data in every iteration. (Specific
example: suppose I want to write a multiplayer game server - for every move a
player makes, I would have to replace ALL game objects, player object, and so
on???).

I looked a bit into Erlang and it seems there could be a workaround by having
lots of threads, so one only needs to change the dataset of one thread at a
time. But how do Clojure or Haskell handle that kind of thing (I don't think
they encourage thousands of threads as Erlang does?).

I think erlang also had a special kind of data structure that would also allow
for kind of mutable data per thread, but really, it all sounded a bit messy to
work with.

How does the paradigm hold up anyway? Isn't there one point eventually when
the processes still interfere with each other? For example when accessing the
database?

~~~
jerf
The answer to your very good question is beyond the scope of what can be
covered in an HN post, so I would suggest that you look at
<http://en.wikipedia.org/wiki/Purely_functional> for a quick answer, or
<http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf> for a more in-depth answer.
After that, you'll know what to Google for. I particularly recommend the
discussion of tree updates in the Wikipedia article to start with, since it
has good diagrams.

That said... multidimensional arrays continues to be a sore point with
functional programs, as far as I know. A variety of purely functional
structures exist that can replicate some parts of the performance guarantees
of traditional arrays, but I am not aware of anything that can cover the full
gamut of uses for a multidimensional array. Usually in this case there is a
functional structure that does what you really need, but ISTM that when you
find yourself needing a multidimensional array, it's because A: it's huge B:
you need fast O(1) updating and C: you need fast O(1) access and that combo is
just killer. (And nowadays, D: you need cache coherence control comes up too.)

Oh, and if I'm reading your question correctly, Erlang process isolation is
not really related to your question. However, I will point out that in Erlang,
two processes will not access the database "at the same time". Two processes
will send messages to the database Erlang-process, which will serve them in
order and send back the replies. When processes and messaging are cheap you
change how you do things; a lot more things get wrapped in processes (files,
socket connections, foreign libraries, pipes to externally running programs
("ports" in Erlang speak, rather unfortunately), etc.) than you'd expect. It's
the fundamental primitive for avoiding contention, it gets used a lot!

------
MindTwister
Just curious, isn't this usually called Conway's game of life?

~~~
tel
Conway's Game of Life has a slightly different rule set. Cellular Automata is
the blanket term for things like this and there are a pretty incredible
variety of rulesets.

