[erlang-questions] Cannot get the hang of single assignment
Dustin Sallings
dustin@REDACTED
Fri Aug 17 22:04:15 CEST 2007
On Aug 17, 2007, at 12:35 , Tom Ayerst wrote:
> I think I am missing something obvious here. I was reading Jim
> Menard's
> account of writing a boids flocking simulator and wanted to have a go.
> Giving each Boid its own process was obvious but, I am very new to
> erlang and was then stumped.
>
> How should I track the state (position and vector) of each Boid?
The general way you do this in a functional language is by passing
the parameters in to a tail-recursive function.
I have no idea what a Boid is, but it seems to have a position and a
vector, and I'm assuming does something to change these. I imagine
your process's main loop would look something like this:
loop(Position, Vector) ->
{NewPosition, NewVector} = compute_new_position_and_vector
(Position, Vector),
loop(NewPosition, NewVector).
--
Dustin Sallings
More information about the erlang-questions
mailing list