On Aug 30, 7:52 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> 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.
>
> A third theory is that neither of the above theories is correct.
>
> Can anyone provide me with some insight?

vector takes individual elements as arguments and map
returns a list. If we simply (vector (map ..)) the entire
list returned by map is seen as a single element. Hence
'apply'.

user=> (vector 1 2 3)
[1 2 3]
user=> (map inc [1 2 3])
(2 3 4)
user=> (vector (map inc [1 2 3]))
[(2 3 4)]
user=> (apply vector (map inc [1 2 3]))
[2 3 4]
user=>

Parth

>
> Thanks,
>
> Rob Lally.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to