redhotmonk a écrit :
> When you look at resulting hash, which you get by calling
> "(initialize-domain 4 4  0.3)",
> you see that the 4-component value vector of every key is "not so"
> random. In fact it is the same vector every time.
> But when I modify the "initialize-domain" function by deleting the
> "seq-of-states" binding, and making a direct call to
> the "get-init-states" function, the result is correct, i.e. for every
> key in the resulting hash, the associated vector is random.
>   
When you have the "seq-of-states" binding, you call get-init-states only 
once. The result is stored in the local named "seq-of-states" and, in 
the loop, (vec (take 4 seq-of-states)) yields the same value at each 
iteration (since seq-of-states doesn't change).
When you inline the call to get-init-states, get-initi-states is called 
at each iteration, returning a different result each time.

It's akin to (let [r (rand)] [r r]) vs [(rand) (rand)].

Hope this helps.

Christophe

-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.blogspot.com/ (en)



--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to