I love the -> and ->> macros, but the problem with them is that you're limited
to the functions you can use. Either all of the functions must be functions
where the argument is passed as the first argument, or they must all be
functions where it's passed in at the end.
I'm making my way through the Joy of Clojure right now, and it mentions that
some people actually use commas to sort of "hint" as to where the argument will
go (with the -> and ->> macros). Why not then just use a macro that actually
listens to your hints?
So I whipped out this --> macro that does just that:
(defmacro -->
([x] x)
([x form]
(if (seq? form)
(with-meta (replace `{~'_ ~x} form) (meta form))
(list form x)
)
)
([x form & more]
`(--> (--> ~x ~form) ~...@more)
)
)
You use it like so:
user=> (--> 3 (+ 1 _ 4) (prn "answer:" _))
"answer:" 8
nil
Perhaps this could be added to the dash-arrow family of macros?
- Greg
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en