On Wed, Oct 22, 2008 at 12:07 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> For interfaces with a single implementation, this sounds fine. And
> closure/zip is a fine example.
>
> But assume I wanto to provide two implementations for such an
> interface, in two separate namespaces. Can I then write client code
> that will work with either one?

Don't dismiss clojure/zip to easily.  The functions defined there
largely defer to functions stored in metadata on the object.  This
means a new type of zip tree can be provided by anyone in any
namespace, simply by returning an object with the appropriate
metadata.

This technique could be extended in other contexts, and there may be
other ways to solve similar problems.

> A related question concerns the interfaces that Clojure already uses:
> ISeq and Number, for example. Can I implement my own data structure in
> Clojure that supports the ISeq interface? Can I implement a new number
> type and have it work with +, -, etc.?

In order to implement Java interfaces such that clojure/seq and such
builtin functions work, you do need to implement a Java class.  This
can be done with 100% Java code by gen-class and possibly the
easier-to-use proxy function.

--Chouser

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

Reply via email to