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

Where do I use eval? I tried looking at the argument to see if it was
called with a string literal vs a symbol, but can't eval a local:

(defmacro foo [x]
  (let [name-as-string# (if (symbol? x) (eval x) x)
        name-as-symbol# (symbol name-as-string#)]
    `(defn ~name-as-symbol# [] ())))

(let [eff "gee"] (foo eff))

> If you don't need the name at run time, why are you using (let [eff
> "gee"] (foo eff)) and not simply (foo gee)?

I'm using let because I'd like to have the name at run time. I'm
defining families of functions to manipulate types of UI elements by
saying (type page-name field-name locator). Without knowing a solution
to my problem, I'm stuck saying the following in order to generate a
bunch of functions to use later in my program...

(txt "registration" "username" "id=Username")
(txt "registration" "password" "id=Password")
(tog "registration" "terms" "id=AcceptTerms")
(nav "registration" "submit" "//html/body/div/form/div/input" "/
SignedIn")

... Instead of this:

(let [page "registration"]
  (txt page "username" "id=Username")
  (txt page "password" "id=Password")
  (tog page "terms" "id=AcceptTerms")
  (nav page "submit" "//html/body/div/form/div/input" "/SignedIn"))

... or interning page as a symbol that sticks around after I'm done
with the definitions? Ew. Un-interning afterwards? Hm.

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