Hi, Milinda.  I'll try to explain my reasoning of the situation.  I always 
find it helpful to macroexpand if I'm having trouble:

;; original version
user=> (macroexpand-1 '(ffff boby))
(clojure.tools.macro/macrolet [(defpop [] tu1282)]  ;; <- undef. lookup
  (clojure.core/defn user/execute [tu1282] boby))

;; Konrad's version
user=> (macroexpand-1 '(ffff-kh body))
(clojure.tools.macro/macrolet [(defpop [] (quote tu__1294__auto__))] ;; <-
  (clojure.core/defn user/execute [tu__1294__auto__] body))

So, I think what is happening here is that the 'defpop' macro defined by 
macrolet needs to return a piece of code (like all macros).  Konrad's 
version returns a symbol, so that's fine.

But the original version is trying to look up the piece of code stored in 
the var tu1282 and return it.  But that variable doesn't exist, so you get 
the CompilerException.  Here is a slight modification of your original that 
explicitly does what Konrad did with auto-gensyms:

(defmacro ffff3 [body]
  (let [x (gensym 'tu)
        defpop-decl (list 'defpop [] (list 'quote x))] ;; <- return the 
quoted symbol, no lookup
  `(macrolet [~defpop-decl]
    (defn execute [~x] ~body))))

Hope that helps,
Leif

On Wednesday, March 5, 2014 12:37:24 PM UTC-5, milinda wrote:
>
> Thanks Konrad. Your unquoting trick worked. But I am not exactly sure how 
> to reason about these types of situations. Can you please shed some lights 
> behind the logic of above unquoting if possible.
>
> Thanks
> Milinda
>
> On Wednesday, March 5, 2014 8:33:03 AM UTC-5, Konrad Hinsen wrote:
>>
>> --On 4 Mar 2014 23:07:27 -0800 milinda <milinda....@gmail.com> wrote: 
>>
>> > I wanted macro to work like following. 
>> > 
>> > 
>> > (ffff (let [x 10] (+ x (defpop)))) 
>> > 
>> > 
>> > This should generate function like 
>> > 
>> > 
>> > (defn execute [tu3455] (let [x 10] (+ x tu3455))) 
>>
>> Try this: 
>>
>>   (defmacro ffff [body] 
>>     `(macrolet [(~'defpop [] 'tu#)] (defn execute [tu#] ~body))) 
>>
>> In action: 
>>
>>   user=> (macroexpand-1 '(ffff (let [x 10] (+ x (defpop))))) 
>>   (clojure.tools.macro/macrolet [(defpop [] (quote tu__818__auto__))] 
>> (clojure.core/defn user/execute [tu__818__auto__] (let [x 10] (+ x 
>> (defpop))))) 
>>
>>   user=> (macroexpand '(ffff (let [x 10] (+ x (defpop))))) 
>>   (do (def user/execute (fn* ([tu__818__auto__] (let* [x 10] (+ x 
>> tu__818__auto__)))))) 
>>
>>
>> Konrad. 
>>
>>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to