Hi All, I am trying to write a simple macro to resolve local symbols and I just can't seem to figure out the right invocation. Here are some commands you can type/paste in a repl:
(def ONE 1) ;define one (def s1 (symbol "ONE")) ;get the symbol (eval s1) ;evaluates to 1, no surprise ;My goal is to pass a symbol into a macro or function, have it evaluate to its defined value, then use it. ;I would like these to happen (add-3 s1) ;Should evaluate to 4 (add-3 (symbol "ONE")) ;Should evaluate to 4 ;The following works, but uses eval, which I am told is less desirable. My current understanding is that a macro is the way to go. (defn add-three-fn[s](+ 3 (eval s))) (add-three-fn (symbol "ONE")) ;4 - it works! ;Here is one of my failed attempts at a macro version: (defmacro add-3 [s] `'(+ 3 ~s)) ;Just puts unevaluated contents in s I'd post other examples, but I can't even see straight anymore. Any help would be appreciated. Thanks, Mark -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.