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