Hi

Here's another macro-noob question. (Thanks for the help on the
previous question and please do let me know if stackoverflow is a more
appropriate place to ask noob questions.)

I'm trying to write a macro (or a function) that defines/declares
specifically named functions. In (let [eff "gee"] (foo eff)) I want
the macro foo to define/declare a function called foo-gee, not foo-
eff. What should I do differently?

First attempt:

(defmacro foo [x]
  (let [name# (symbol (str "foo-" x))]
    `(defn ~name# [] ())))

(let [eff "gee"] (foo eff))
=> #'user/foo-eff

Second attempt:

(defmacro foo [x]
  `(let [name# (symbol (str "foo-" ~x))]
     (defn name# [] ())))

(let [eff "gee"] (foo eff))
=> #'user/name__4807__auto__

Third attempt:

(defmacro foo [x]
  `(let [name# (symbol (str "foo-" ~x))]
     (defn ~name# [] ())))

(let [eff "gee"] (foo eff))
=> First argument to def must be a Symbol
   [Thrown class java.lang.Exception]

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