Hi,
Am 28.10.2010 um 21:55 schrieb Raoul Duke:
> i've heard other folks in the Clojure world say that
> if you aren't using macros, then sorta why bother use a Lisp since you
> are missing out on one of the most powerful differentiators.
These people ^^^ should listen carefully to those people vvv.
> i've heard that in CL land, one is told to avoid macros as
> long as possible. Reading about Conj it sounds like some
> folks say stay away from macros if you can.
> any way of teasing out when macros are ok? :-) i mean, are they only
> ok for the internals of the Clojure system?
No. They are perfectly ok for any type of project. It's just a matter of being
the right tool for the job. Of course it's ok to use them, but please in a
responsible manner. If you don't need a macro, don't use one. Similar to: if
you don't need a Ref, don't use one.
Rule of thumb: can you write it as a function, do it. (Add a macro just to
sugar away any ugliness). If you can't write it as a function, you obviously
need a macro. Then use one.
Examples:
(with-bindings* {#'foo 5} (fn [] (do stuff))) works well as a function:
(defn with-bindings*
[bindings thunk]
(push-thread-bindings bindings)
(try
(thunk)
(finally
(pop-thread-bindings))))
Just do away the ugliness:
(defmacro with-bindings
[bindings & body]
`(with-bindings* ~bindings (fn [] ~...@body)))
To eg. def things you need a macro. Here a function won't work.
Hope this helps.
Sincerely
Meikel
--
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