Seems like the expansion is trying to put the function's value in there, 
and this has already been compiled. If the function' code is expanded 
in-place it works.

user=> (defmacro bar 
  [a] 
  (let [b (keyword a) 
        f `(fn [& args#] ~b)] 
    `(deftype ~a [] 
       clojure.lang.ILookup 
       (valAt [this# k#] (~f this# k#)) 
       (valAt [this# k# d#] (~f this# k# d#))))) 
#'user/bar
user=> (bar alex)
user.alex
user=> (def a (alex.))                                  
#'user/a
user=> (:foo a :bar)                                    
:alex


On Saturday, April 28, 2012 8:43:21 AM UTC-7, Shantanu Kumar wrote:
>
> Hi, 
>
> I am running into error when using macros with deftype. For example, 
> when I use the macro `foo` it works fine: 
>
> (defmacro foo 
>   [a] 
>   (let [b (keyword a)] 
>     `(do ~b))) 
>
> (foo alex) 
> => :b 
> whereas, when I use the macro `bar`: 
>
> (defmacro bar 
>   [a] 
>   (let [b (keyword a) 
>         f (fn [& args] b)] 
>     `(deftype ~a [] 
>        clojure.lang.ILookup 
>        (valAt [this# k#] (~f this# k#)) 
>        (valAt [this# k# d#] (~f this# k# d#))))) 
>
> (bar alex) 
>
> I get the following error: 
> CompilerException java.lang.ExceptionInInitializerError, compiling: 
> (NO_SOURCE_PATH:87) 
>
> Can somebody help me understand what am I doing wrong here. 
>
> Shantanu

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