Here's a macro that generalizes the two 'threading' macros -> and ->>.

It works by using the idea of 'nesting marker' (from Oz) to specify
where the result of the previous form should be nested in the
subsequent form.

(defmacro -$>
  "Threads the expr through the forms. Inserts x into
  the first form at the position marked by the $ symbol.
  If the second form is not a list then it behaves as ->.
  If there are more forms, inserts the first form into the second
  form at the position marked by the $ symbol, etc."
  ([x form] (if (seq? form)
              (let [split (split-with (partial (complement =) '$)
form)]
                `(~@(first split) ~x ~@(rest (second split))))
              (list form x)))
  ([x form & more] `(-$> (-$> ~x ~form) ~...@more)))

If this is any use to anyone (esp. anyone who has a CA) then consider
it public domain.

Any improvements appreciated!


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