On Mon, Dec 28, 2009 at 10:37 PM, Allen Rohner <aroh...@gmail.com> wrote:
> 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?
>

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

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