Hi achim, That looks like a fine start. Thanks for doing it!
This part concerns me: > Note: Since clojure maps are no java maps, they can't be equal to java > maps. This holds for wrapped clojure maps as well - surprisingly (in a > bad sense), but i don't see a way around this: > > (= (doto (HashMap.) (put 1 2)) {1 2}) > -> false > > (= (jmap {1 2}) {1 2}) > -> false Here's my understanding of how = works in Clojure (corrections welcome): Clojure defines "=" (for all types) as "has the same value". For two maps A and B (of any concrete type) this means: For every key in A there exists a key in B that is = to it. For every key in B there exists a key in A that is = to it. For every key k in A, the value associated with k in A is = to the value associated with k in B The map types that we have now implement this. I think it's very important that jmap fit in with that definition of "=". What prevents jmap from participating in this same check? If there are more changes to existing Clojure code that are necessary to support this, I think they should be part of a jmap patch. --Steve On Sep 29, 2008, at 2:30 PM, Achim Passen wrote: > > Hi! > > Here's a patch to add java.util.Map support to clojure maps, along > with some example code. This my first java code in quite some time, so > if you notice i'm doing anything odd or incorrect, please don't > hesitate to comment. > > http://groups.google.com/group/clojure/web/jmap.diff > http://groups.google.com/group/clojure/web/jmap-examples.clj > > It has been discussed why clojure maps do not implement the > java.util.Map interface (short version: j.u.Map and j.u.Collection > clash, Collection being preferrable). This patch provides two > functions, "jmap" and "cmap", the former to wrap a clojure map in a > flyweight wrapper that provides the j.u.Map implementations, the > latter to unwrap it again. > > The results of a calls to j.u.Map methods are automatically wrapped > again if they return maps, so from the java point of view, nested > clojure maps show up as nested java maps. > > From the clojure point of view, wrapped maps retain most of the > functionality of their unwrapped counterparts: they can be invoked, > assoced and conjed, etc., the result being a full-featured clojure map > in each case. However ... > > Note: Since clojure maps are no java maps, they can't be equal to java > maps. This holds for wrapped clojure maps as well - surprisingly (in a > bad sense), but i don't see a way around this: > > (= (doto (HashMap.) (put 1 2)) {1 2}) > -> false > > (= (jmap {1 2}) {1 2}) > -> false > > Efficiency: lookup key- and mapentry-sets on wrapped maps should be > fast, since they just delegate calls to the clojure map inside. Lookup > on the values takes linear time though, and as far as i can see, we > can't do better, because the values themselves are not structured for > fast access in clojure maps. > > Comments are most welcome! > > Kind regards, > achim > > -- > http://rauschabstand.twoday.net > > > --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---