Am Dienstag, 13. November 2012 12:15:17 UTC+1 schrieb thorwil: > > On 11/13/2012 11:06 AM, Johannes wrote: > > 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)))))))) > > > 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? > > I guess the problem is that you created :x using symbol, so it is not > recognized as a key. > > But the whole approach, starting with creating names to def to inside a > macro, is troublesome. This makes it hard to follow what's going on. If > you provide a larger context of what you are trying to accomplish, I'm > sure someone can suggest a much better approach. > I am trying to build an alternative record building macro. For example
(define-record point [x y]) should define - a new type point - a constructor make-point - a type checker point? - and 2 getters point-x and point-y 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