merge doesn't work on deftypes implementing IPersistentMap

66 views
Skip to first unread message

Allen Rohner

unread,
Dec 28, 2009, 10:37:19 PM12/28/09
to Clojure
I tried to call merge on a deftype implementing IPersistentMap, and
got an exception:

user> (deftype Foo [a b] clojure.lang.IPersistentMap)
#'user/Foo

user> (Foo 1 2)
#:Foo{:a 1, :b 2}
user> (merge (Foo 1 2) {:a 3})
; Evaluation aborted.

nth not supported on this type: PersistentArrayMap
[Thrown class java.lang.UnsupportedOperationException]

Restarts:
0: [ABORT] Return to SLIME's top level.

Backtrace:
0: clojure.lang.RT.nth(RT.java:811)
1: user.Foo__15735.cons(NO_SOURCE_FILE:1)
2: clojure.lang.RT.conj(RT.java:534)
3: clojure.core$conj__3951.invoke(core.clj:67)
4: clojure.core$merge__4623$fn__4624.invoke(core.clj:1919)
5: clojure.core$reduce__4135.invoke(core.clj:665)
6: clojure.core$reduce__4135.invoke(core.clj:656)
7: clojure.core$merge__4623.doInvoke(core.clj:1919)
8: clojure.lang.RestFn.invoke(RestFn.java:422)
9: user$eval__15820.invoke(NO_SOURCE_FILE:1)
10: clojure.lang.Compiler.eval(Compiler.java:5258)
11: clojure.lang.Compiler.eval(Compiler.java:5226)
12: clojure.core$eval__4674.invoke(core.clj:2018)
--more--


Interestingly, drewr on IRC pointed out that
(merge {:a 3} (Foo 1 2)) works. I then figured out that
(merge {} (Foo 1 2) {:a 3}) works.

This seems like a bug to me. Is it?

Allen


Rich Hickey

unread,
Dec 29, 2009, 2:51:27 PM12/29/09
to clo...@googlegroups.com

As we discussed in #clojure IRC, conj for deftypes does not yet
support all the flexibility of conj for e.g. hash-maps, in particular,
the conjing of another map. It does support vectors and map entries.

Rich

Raoul Duke

unread,
Dec 29, 2009, 3:14:29 PM12/29/09
to clo...@googlegroups.com
>> This seems like a bug to me. Is it?

> As we discussed in #clojure IRC, conj for deftypes does not yet
> support all the flexibility of conj for e.g. hash-maps, in particular,
> the conjing of another map. It does support vectors and map entries.

i'm hoping the "yet" part means it is slated to maybe someday be upgraded?

Allen Rohner

unread,
Dec 30, 2009, 3:43:59 PM12/30/09
to Clojure
> i'm hoping the "yet" part means it is slated to maybe someday be upgraded?

I've filed a bug and submitted a patch. Assuming my fix is acceptable,
this should be in soon.

https://www.assembla.com/spaces/clojure/tickets/231-deftype-cons-doesn-t-support-maps-

Reply all
Reply to author
Forward
0 new messages