Re: Why does (conj (transient {}) {}) fail with CCE?

2012-08-09 Thread dennis zhuang
you must use conj! instead of conj.
在 2012-8-9 PM8:49,Jacek Laskowski ja...@japila.pl写道:

 Hi,

 I've been digging into the sources of Clojure and found frequencies.
 There's the transient function and I thought I'd use it with a map and
 conj. Why does this fail?

 user= (conj {} {:y 1})
 {:y 1}
 user= (conj (transient {}) {:y 1})
 ClassCastException   [trace missing]

 I ran into the issue before and got a more comprehensible exception.

 ClassCastException clojure.lang.PersistentArrayMap$TransientArrayMap
 cannot be cast to clojure.lang.IPersistentCollection
 clojure.core/conj (core.clj:83)

 I can't explain why the exception is reported in two different versions.

 Should the exception be thrown? What's the rationale behind
 TransientArrayMap *not* being a IPersistentCollection?

 Jacek

 --
 Jacek Laskowski
 Functional languages (Clojure), Java EE, and IBM WebSphere -
 http://blog.japila.pl
 Never discourage anyone who continually makes progress, no matter how
 slow. Plato

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


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

Re: Why does (conj (transient {}) {}) fail with CCE?

2012-08-09 Thread Baishampayan Ghose
On Thu, Aug 9, 2012 at 6:19 PM, Jacek Laskowski ja...@japila.pl wrote:
 What's the rationale behind
 TransientArrayMap *not* being a IPersistentCollection?

A transient map can't be a persistent map at the same time. You
need to use the transient version of conj, called conj! to conjoin
something into a transient map and then use persistent! to get a
persistent version back.

Please read the documentation for more background http://clojure.org/Transients

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at gmail.com

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


Re: Why does (conj (transient {}) {}) fail with CCE?

2012-08-09 Thread Jacek Laskowski
On Thu, Aug 9, 2012 at 2:54 PM, Baishampayan Ghose b.gh...@gmail.com wrote:

 A transient map can't be a persistent map at the same time. You
 need to use the transient version of conj, called conj! to conjoin
 something into a transient map and then use persistent! to get a
 persistent version back.

 Please read the documentation for more background 
 http://clojure.org/Transients

Thanks! It's so much clearer now.

Jacek

-- 
Jacek Laskowski
Functional languages (Clojure), Java EE, and IBM WebSphere -
http://blog.japila.pl
Never discourage anyone who continually makes progress, no matter how
slow. Plato

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