I've been using Clojure for a couple months, so while I feel comfortable with it, I'm not certain whether some unusual behavior I encountered is a bug or a lack of understanding on my part. (I suspect the latter.)
The context arose from using Clojure reflection to inspect a class generated by Apache Thrift <http://thrift.apache.org>. Such classes have a static, unmodifiable map describing the members of the class. I wrote a function to extract the keys of this map; it initially appears to work, but "def"ing the results to a symbol and repeatedly using that symbol returns inconsistent results. I've boiled it down to a smaller example that replicates the result: (gist available <https://gist.github.com/jameswarren/6799309>) // Java class public class DummyClass { public enum DummyEnum { FIRST, SECOND, THIRD } public static final Map<DummyEnum, String> dummyMap; static { Map<DummyEnum, String> tmpMap = new EnumMap<DummyEnum, String>(DummyEnum.class); tmpMap.put(DummyEnum.FIRST, "first"); tmpMap.put(DummyEnum.SECOND, "second"); tmpMap.put(DummyEnum.THIRD, "third"); dummyMap = Collections.unmodifiableMap(tmpMap); } } // Clojure ns (ns refbug.core (:import [refbug DummyClass])) (defn foo [^Class c] ;; note: (into [] (keys (clojure.lang.Reflector/getStaticField c "dummyMap")))) works (keys (clojure.lang.Reflector/getStaticField c "dummyMap"))) (def m (foo DummyClass)) (println m) ;; (#<DummyEnum FIRST> #<DummyEnum SECOND> #<DummyEnum THIRD>) (println m) ;; (#<DummyEnum THIRD> #<DummyEnum THIRD> #<DummyEnum THIRD>) Two different values upon successive calls using m. Is this expected? And if so, why? Many thanks, -James -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.