On Fri, Nov 14, 2008 at 10:51 PM, Bradbev <[EMAIL PROTECTED]> wrote:
>
> I thought up an interesting issue the other night.  If you map a
> function over a seq of refs, then change the refs & look at the map
> return value (which will convert it from lazy to ...?  Hmm, what's the
> word - motivated?) then you will get the current value of the refs.
>
> The example code is
> (def refs (into [] (map #(ref %) (range 10))))
> (def dref (map deref refs))
>
> (doseq r refs
>  (dosync
>   (commute r #(* 2 %))))
>
> (println dref)
>
> When you consider how map works, this actually makes total sense.
> However, I think that it is something of a gotcha.
> Normally you don't need to know that map returns a lazy seq, because
> normally you would be mapping over immutable data.  But if you happen
> to map over seqs that have refs, then you might have problems.  I find
> it conceptually jarring - normally laziness is a transparent
> abstraction.
>
> I guess the main reason I'm posting this is to point out the issue.  I
> wonder if this gotcha should be highlighted somewhere in the official
> documentation, or am I making a mountain out of a molehill?

The seq documentation says this:

"Robust programs should not mutate arrays or Iterables that have seqs on them."

Perhaps something similar should be mentioned on the data structures page?

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
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