PATCH: java.util.List and java.util.Set implementation for Clojure native collections

14 views
Skip to first unread message

Meredydd

unread,
Jul 22, 2008, 10:54:42 AM7/22/08
to Clojure
See attached, a patch against current SVN head (rev 951) which makes native
Clojure vectors and sequences implement java.util.List, and sets implement
java.util.Set. Also see attached a mini test script.

The second patch, which is dependent upon the first, alters the RT.print()
function (aka (pr)) to print all java.util.Sets in #{...} reader notation,
and all Lists in [...] notation. Native Java maps are also printed in {...}
notation.

Meredydd

clojure-list-test.clj
2008.07.22.List_Set_support.patch
2008.07.22.Write_collections_natively.patch

Stuart Sierra

unread,
Jul 25, 2008, 5:23:23 PM7/25/08
to Clojure
I think implementing the Java Collections sub-interfaces (List, Set,
Map) is a good idea for Java interoperability, even if they have to be
read-only.

-Stuart
> clojure-list-test.clj
> 1KDownload
>
> 2008.07.22.List_Set_support.patch
> 8KDownload
>
> 2008.07.22.Write_collections_natively.patch
> 1KDownload

Rich Hickey

unread,
Jul 25, 2008, 5:59:04 PM7/25/08
to Clojure


On Jul 25, 5:23 pm, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:
> I think implementing the Java Collections sub-interfaces (List, Set,
> Map) is a good idea for Java interoperability, even if they have to be
> read-only.
>

I've made vectors implement List and sets Set. List is a very poor
match for non-indexed sequences.

As far as Maps, unfortunately the collection API design precludes a
class implementing both Collection and Map (conflicting remove
signatures). All Clojure collections implement Collection. Making maps
implement Map would be a breaking change.

Rich
Reply all
Reply to author
Forward
0 new messages