On Tue, Jun 16, 2009 at 5:22 PM, Chris Dean<ctd...@sokitomi.com> wrote:
>
>
> I'm using the embedded key/value database Tokyo Cabinet on a project.
> We have functions that use the database and some of the them are very
> similar to the core clojure functions that access a map.
>
> For example, the Tokyo Cabinet functions db-count, db-seq, and db-get
> correspond nicely to count, seq, and get.
>
> What's the best way to augment the function named count (.et.al.) to
> provide the same functionality as db-count ?
>
> It seems like I should be able to use multimethods, but don't see how
> that would work.

It won't.  Most clojure core functions are not multimethods -- partly
because they don't really need to be, and partly be cause they must be
fast.

> I suppose I could write a Java wrapper class that implements the proper
> interfaces.  Either using plain old Java or the Clojure proxy/gen-class
> functions.

That's probably the right way to go.  If you've got your own object
(even if it's really just a Clojure hash-map with Tokyo Cabinet
handles in it), and you want to be able to use Clojure core functions
on it, proxy will probably work nicely for you.  The core functions
generally depend on specific Java interfaces that are defined in the
clojure.lang package, and wrapping a proxy around that is usually
pretty easy.

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

Reply via email to