Reported by wolfe.a.jason, Feb 04, 2009
Describe the feature/change.
Add "keyset" to Clojure; make .keySet for APersistentMap return an
IPersistentSet
Was this discussed on the group? If so, please provide a link to the
discussion:
http://groups.google.com/group/clojure/browse_thread/thread/66e708e477ae992f/ff3d8d588068b60e?hl=en#ff3d8d588068b60e
-----------------------------------------------------
A patch is attached. Some notes:
I chose to add a "keyset" function, rather than change the existing "keys",
so as to avoid breaking anything.
The corresponding RT.keyset function just calls .keySet on the argument.
I would have liked to have "keyset"return an IPersistentSet even when
passed a (non-Clojure) java.util.Map, but this seems impossible to do in
sublinear time because of essentially the same limitation mentioned in the
above thread (the Map interface does not support getKey() or entryAt()) --
assuming, again, that "get" is supposed to return the actual (identical?)
key in a set, and not just an .equal key.
I then changed the implementation of .keySet for APersistentMap to
essentially copy APersistentSet. A more concise alternative would have
been to extend APersistentSet and override the .get method, but that made
me a bit nervous (since if APeristentSet changed this could break).
Anyway, this is my first patch for the Java side of Clojure, and I'm not
yet solid on the conventions and aesthetics, so
comments/questions/criticisms/requests for revisions are very welcome.