I'm new to Clojure and just getting my head around macros. As an
exercise I was trying different ways to wrap making a proxy for
java.util.Comparator and came up with two alternatives. I'm really not
sure how to judge what would favour one solution over the other, and
I'm curious if one style is preferred over the other around the
Clojure community.

First some data:

    (def things #{:q :w :e :r :t :y :a :s :d})
    (defn inverse-compare [a b] (* -1 (compare a b)))

Using a macro to generate a proxy to change sort order:

    (defmacro cmprtr [f] `(proxy [java.util.Comparator] [] (compare
[a# b#] (~f a# b#))))
    (sort (cmprtr inverse-compare) things)

Using a simple function to generate the proxy:

    (defn cmpprx [f] (proxy [java.util.Comparator] [] (compare [a b]
(f a b))))
    (sort (cmpprx inverse-compare) things)


Thanks,
Julian.

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