Controlling symbol generation in Clojure macros -


I am trying to create a close macro (as a self-learning exercise) to implement the function Code for integer and the sum of the results, eg

f (1) + f (2) + f (3)

This is my attempt (Defmacro though (test) [fancy n] `(fn [x #] (+ ~ @ (map (fn [i]` (~ fx x #)) ( Class N))))

X # is going wrong with gensym and I have two different axes C versions end and therefore the function does not work:

  (Macroxpand '(testim in 3))  

returns:

  (fn * ([x__809__auto__] (close.core / + (inc x__808__auto__) (inc x__808__auto__) (inc x__808__auto__))))  

Which I want to separate from different versions of 80 9 and 808.

What am I doing wrong? I thought that auto jeans actually created a unique symbol for such a purpose Was for Is there a better way to do this?

foo # - genes for style are valid only within syntax-quotes Where they were built. In your code, two x # s are created in separate syntax-bidding blocks:

  (defmacro testsum [func n] `(fn [x #] ( + @ (Map (fn [i] `(~ func x #)) (category n))) ^ - s-q1 ^ -kunko ^ - s-q2  

fix it To do, use a clear (gensym) call:

  (defmacro tests [func n] (let [x (gensum "x")] `  

and macro expansion (< Code> (macroexpand '(Testing Ink 3)) ):

  (fn * ([x4966] (close x + 4) (inc x4966) (inc x4966) (inc X4966))))  

Comments