As Ken said, you have to remember macros expand at compile time.
Think of a macro call as "folded up code" that the compiler unfolds
for you.  A macro saves you from writing repetitive code.

But if you are trying to define a function whose name isn't known
until runtime, that's a whole different thing.  Doesn't really make
sense to me, since the reason you want to define a var for your fn is
presumably because you have code elsewhere that calls it.  But if both
the definition and call to the fn aren't known until runtime, I don't
see the need for a var. Perhaps you could just use a map of names
(either strings or keywords or even symbols) to anonymous fn's?  At
runtime you can add fns to the map, and later pick the fn and call it?

(def fns (atom {})

(defn add-fn [name f]
  (swap! fns assoc name f))

(defn call-fn [name]
  ((@fns name)))

something like that.  No macros needed.

On Jun 2, 10:34 pm, Ken Wesson <kwess...@gmail.com> wrote:
> On Thu, Jun 2, 2011 at 10:06 PM, nil <ache...@gmail.com> wrote:
> > 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?
>
> The problem here is that macros run at compile time, but let bindings
> exist at run time.
>
> If you need the name to be determined at run time you will need to use eval.
>
> If you don't need the name at run time, why are you using (let [eff
> "gee"] (foo eff)) and not simply (foo gee)?
>
> Please state your requirements clearly.
> --
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.

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