I tried this. But couldn't achieve what I wanted. Below is the macro I 
wrote by utilizing macro let

(defmacro ffff [body]
  (let [x (gensym 'tu)
        defpop-decl
        (list 'defpop [] x)]
    `(macrolet [~defpop-decl]
               (defn execute [~x] ~body))))

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

But above macro complain saying "CompilerException 
java.lang.RuntimeException: Unable to resolve symbol: tu3455 in this 
context.

Looks like I am doing something wrong or I am not understanding how clojure 
read, evaluation and macros work.

Please let me know if anyone know way to achieve what I want using macros 
and macrolet.

Thanks
Milinda
On Tuesday, March 4, 2014 2:28:06 PM UTC-5, milinda wrote:
>
> Thanks Jason. I'll try this. 
>
> Milinda
>
> On Tuesday, March 4, 2014 1:35:39 PM UTC-5, Jason Felice wrote:
>>
>> Can you use macrolet from here: https://github.com/clojure/tools.macro ?
>>
>>
>> On Tue, Mar 4, 2014 at 11:30 AM, milinda <milinda....@gmail.com> wrote:
>>
>>> I wanted to achive following inside a macro. Lets say I have a macro 
>>> called deffilter which can use in following manner.
>>>
>>> (deffilter split-sentence ["sentence"] ["word"]
>>>            (work {} 
>>>                  (let [tuple (pop) 
>>>                        words (s/split (value-at tuple 0) " ")] 
>>>                    (doseq [w words]
>>>                     (push [w] :anchor tuple))))) 
>>>
>>> I need to transform above work section to something looks like following.
>>>
>>> (work [tuple1234]
>>>    (let [tuple tuple1234
>>>           words (s/split (value-at tuple 0) " ")]
>>>          (doseq [w words]
>>>                     (push [w] :anchor tuple))))
>>>
>>> (pop) should be replaced by tuple1234 like string which is same as 
>>> parameter to work function.
>>>
>>> Really appriciate if someone can point me a way to achieve this. I am 
>>> not sure having pop as another macro is viable because I need to use the 
>>> same name as input parameter to work function.
>>>
>>> Thanks
>>> Milinda
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>

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