You want an explicit gensym that scopes over both positions.

(defmacro a-macro
  [m]
  (let [f (gensym "f)]
    `(fn [~f]
       ~(for [i# m]
          `(*  (:val ~f) ~i# )))))

Thanks,
Ambrose

On Wed, Aug 26, 2015 at 5:07 PM, Rafik NACCACHE <rafik.nacca...@gmail.com>
wrote:

> Suppose I have the following macro, which generates a function that does
> some repetitive generation, let's say:
>
> (defmacro a-macro
>   [m]
>   `(fn [f#]
>      ~(for [i# m]
>         `(*  (:val f#) ~i# ))))
>
> Note how I start with a quoted block in which I emit the fn header, and in
> which I use a gensym to capture its input, F#. I unquote to do my iterative
> processing, then I quote again to emit my macro output.
>
> If I macroexpand this:
> (clojure.pprint/pprint  (macroexpand '(a-macro (1 2 3))))
>
> I get :
>
> (fn*
>  ([f__11552__auto__]
>   ((clojure.core/* (:val f__11551__auto__) 1)
>    (clojure.core/* (:val f__11551__auto__) 2)
>    (clojure.core/* (:val f__11551__auto__) 3))))
>
> And I have a problem. The auto gensym for args declaration (...11522) is
> different from the gensyms applying this arg in my generated function body
> (...11551), so I cannot call my function.
>
> Any Idea why is that? And Can you please help me to sort this kind of
> situation?
>
> Thank you;
>
> Rafik
>
> --
> 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/d/optout.
>

-- 
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/d/optout.

Reply via email to