You can't convert to keyword simply by (str ":" (str (first
components))...you need the (keyword (first components))...also why is
your argument (symbol "obj")? I'd prefer obj# or (gensym obj)...
Jim
On 13/11/12 10:06, Johannes wrote:
Hi,
I define a record
(defrecord point [x y])
and the following macro:
(defmacro drg
[typename components]
`(def ~(symbol (str typename "-" (str (first components))))
(fn [~(symbol "obj")] (get ~(symbol "obj") ~(symbol (str ":" (str
(first components))))))))
the call
user> (macroexpand-1 '(drg point [x y]))
delivers what I expect:
(def point-x (clojure.core/fn [obj] (clojure.core/get obj :x)))
Evalutating this expression at the repl delivers what I expect:
user> (def point-x (clojure.core/fn [obj] (clojure.core/get obj :x)))
#'user/point-x
But calling the macro results in an error message:
user> (drg point [x y])
CompilerException java.lang.RuntimeException: Unable to resolve
symbol: :x in this context, compiling:(NO_SOURCE_PATH:1)
Can anyone tell me what my mistake is?
Johannes
--
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 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