On Aug 30, 10:52 am, "
rob.la...@gmail.com" <
rob.la...@gmail.com>
wrote:
> In the ant simulation the world function looks like this
>
> (def world
> (apply vector
> (map (fn [_]
> (apply vector (map (fn [_] (ref (struct cell 0 0)))
> (range dim))))
> (range dim))))
>
> I'm not sure why the calls to '(apply vector' are required. I have two
> theories:
>
> * It is to work round the lazy nature of map and force the creation of
> all of the refs. If this is the case, can anyone enlighten me as to
> why this might be necessary?
> * It is a performance optimisation to make lookups of faster later.
Yes, we want to look up by index, and so use a vector.
Note that (apply vector s) is never needed now, use (vec s) instead.
Rich