On Mon, Aug 3, 2009 at 7:27 PM, CuppoJava <patrickli_2...@hotmail.com>wrote:

>
> Hi Rich,
> This is a very useful addition thanks. I personally find the O(1)
> transformation to and back most useful.
>
> I have a question about capturing the return values of conj! and
> assoc!.
>
> in this code:
> (let [v (transient [])
>       v2 (conj! v 0)])
>
> v2 is the captured return value from conj!, which you're supposed to
> use for future operations. But what does v point to now?


The site says: "Note in particular that transients are not designed to be
bashed in-place. You must capture and use the return value in the next
call."

So v is not safe to use. Probably either using it throws an exception or
else it points to a node in the implementation of v2, but not necessarily
the correct "head" or "root" node, so that using it will have questionable
effects. (Common Lisp has similar cases. Let l be a list, s the results of
calling sort on l, and examine l. It's likely to now be a tail of, but not
the entirety of, s, because it points to the same cons it always did and
sort moved that cons so it isn't the head of the list any more, while
returning the head cons. This doesn't happen with Clojure's sort because
Clojure's sort doesn't mutate; in Clojure, l stays pointing to the unsorted
list and s points to a sorted version. But these new transient mutators may
behave more like Common Lisp's sequence mutators in this regard. Rich?)

--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
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