> So the problem is solved for me, although I have to use eval. I'm not > sure exactly how dirty this trick is and especially *why* it is > considered a "smell". I read it on Paul Graham's "On Lisp" and he > vehemently opposes its use but he doesn't explain why or where it is > acceptable. Note that he also considered Common Lisp "let*" a smell, > which is standard practice in Clojure (and in fact there's no > equivalent of Common Lisp "let"). So maybe we are just making too much > a big deal of this "eval" thing. >
It is considered bad because eval is for dynamic evaluation. In this case you use it at macro time, which shouldn't be necessary most of the time. (defn my-complex-function [] ....) (defmacro insert-the-result-of-the-complex-function [] (my-complex-function)) In your case, as often for strange macro, first write a function that does the job: (defn extract-keyword-and-generate-code [].....) (defmacro generate-methods [] `(do ~@(extract-keyword-and-generate-the-code))) If you have to use an eval, I find it nicer to use it to compute the code, not to actually define things. (defmacro generate-methods [expr] `(do ~@(extract-keyword-and-generate-the-code (eval expr)))) That way you can often work the eval out, by limiting the kind of possible exprs. (If it is only a symbol or a list of keywords, for example) Anyway, that's just a suggestion. Your solution works too. Best, Nicolas. -- 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