(symbol (str ":" (str (first components)))) should be (keyword (first
components))
In your expansion, :x is not a keyword but a symbol starting by a colon --
the symbol fn performs no validation on its input.
When you copied/pasted it for evaluation it was then read as a keyword.

Btw I'm a little worried: are you planning to generate accessors for your
fields or are you just toying with macros?

hth,

Christophe


On Tue, Nov 13, 2012 at 11:06 AM, Johannes <bra...@nordakademie.de> 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




-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (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

Reply via email to