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