Okay. So I grasped some understanding from going through Meikel's
macro with a micron comb.

Here's my version: it's a little more general (it can accept any
number of arguments), and little cleaner.
----------------
(defmacro defblockfn [function params & body]
  (let [butlast_params (butlast params)]
    `(do (defn func# ~params ~...@body)
         (defmacro ~function [...@butlast_params & tail#]
           `(~'func# ~...@butlast_params (fn [] ~...@tail#))))))
-----------------

This allows us to define "modifier" macros, like such:

(defblockfn with_surrounding_text [text func]
  (println text)
  (func)
  (println text))

And you can use it like such:

(with_surrounding_text "surround"
  (println "within surrounding text: line1")
  (println "within surrounding text: line2"))

I'm personally using it to wrap openGL commands:
(defblockfn with_shape [shape func]
  (glBegin shape)
  (func)
  (glEnd))

so that I can type:

(with_shape GL11/GL_QUADS
  (glVertex ...)
  (glVertex ...))

The point of this macro is not to accomplish any specific function.
It's to allow you to define your own "wrapping" functions.

Thanks to Meikel and Sean for their input and help.
  -Patrick
--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to