Re: Weird GenSyms behaviour across different quoted blocks in a macro

2015-08-26 Thread Timothy Baldridge
Auto generated symbols (x# style) are only valid within a single syntax
quote form. Instead declare the symbol ahead of time, something like this:


(let [fsym (gensym "f_)]
  `(fn [~fsym]
 ~@(for [x (range 10]
 `(println ~fsym ~x

Hope this helps.

Timothy

On Wed, Aug 26, 2015 at 3:07 PM, Rafik NACCACHE 
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.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

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


Re: Weird GenSyms behaviour across different quoted blocks in a macro

2015-08-26 Thread Leon Grapenthin
What Ambrose said and:

There is no need to use a hash for i in the for form. It is misleading 
because one thinks it will become a generated symbol as part of the 
generated form which is untrue.

On Wednesday, August 26, 2015 at 11:08:12 PM UTC+2, Rafik NACCACHE 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.


Re: Weird GenSyms behaviour across different quoted blocks in a macro

2015-08-26 Thread Ben Wolfson
unify-gensyms from potemkin will fix this:
https://github.com/ztellman/potemkin


On Wed, Aug 26, 2015 at 2:07 PM, Rafik NACCACHE 
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.
>



-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

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


Re: Weird GenSyms behaviour across different quoted blocks in a macro

2015-08-26 Thread Ambrose Bonnaire-Sergeant
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 
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.


Weird GenSyms behaviour across different quoted blocks in a macro

2015-08-26 Thread Rafik NACCACHE
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.