When figuring these things out it can sometimes help to look at the
implementations of stuff like defn (in clojure.core).

I'll leave it as an exercise to you, but you should note that you may
want to name-space qualify the database (depending on what you are
doing with it and where the database symbol is), or make it so that
you can pass the database from the top level macro.

(defn reddis-wrap-body [[params & body]]
    (list params `(reddis/with-server *db* ~...@body)))

(defn reddis-wrap-bodies? [params-bodies?]
  (if (vector? (first params-bodies?))
    (reddis-wrap-body params-bodies?)
    (map reddis-wrap-body params-bodies?)))

(defn defreddis-sub
  ([name doc-string attr-map params-body]
     `(defn ~name ~doc-string ~attr-map ~@(wrap-bodies? params-body)))
  ([name doc-string-or-attr-map params-body]
     `(defn ~name ~doc-string-or-attr-map ~@(wrap-bodies? params-
body)))
  ([name params-body]
     `(defn ~name ~@(wrap-bodies? params-body))))

(defmacro defreddis [name & fdecl]
  (cond (or (vector? (first fdecl)) (list? (first fdecl)))
        (defredis-sub name fdecl)
        (or (vector? (second fdecl)) (list? (second fdecl)))
        (defredis-sub name (first fdecl) (rest fdecl))
        (or (vector? (nth fdecl 2)) (list (nth fdecl 2)))
        (defredis-sub name (first fdecl) (second fdecl) (rest (rest
fdecl)))))

---
I have tested and macro-expanded the macro (it looks right to me), but
I can't be sure it actually runs as I don't have reddis setup.
--~--~---------~--~----~------------~-------~--~----~
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