title: Clojure Nested Macro
body: <p>Is it possible to macro returned macro? I would like to simplify the code maximum, and I can do this using a macro that returns the function. However, it is too much overhead and it is too slow. To keep the code more readable, I did not use type hints, but even with them my code is ~ 5x slower.</p>
  
  <p>My English is not very precise, so I write what I have and what I wanted to have.</p>
  
  <p>I have this...</p>
  
  <pre class="lang-clj prettyprint-override"><code>(defmacro series [java-array]
    `(fn 
       ([i#]
        (aget ~java-array i#))
       ([start# stop#]
        (let [limit# (unchecked-subtract-int stop# start#)
              result# (double-array limit#)]
         (loop [i# 0]
          (if (&lt; i# limit#)
            (let [r# (double (aget ~java-array i#))]
              (aset result# i# r#)
              (recur (inc i#)))
            result#))))))
  </code></pre>
  
  <p>I want something like this...</p>
  
  <pre class="lang-clj prettyprint-override"><code>(defmacro series [java-array]
    `(defmacro blabla 
       ([i#]
        `(aget ~~java-array i#))
       ([start# stop#]
        `(let [limit# (unchecked-subtract-int stop# start#)
               result# (double-array limit#)]
           (loop [i# 0]
             (if (&lt; i# limit#)
               (let [r# (double (aget ~~java-array i#))]
                 (aset result# i# r#)
                 (recur (inc i#)))
               result#))))))
  </code></pre>
  
  <p>But when I call this...</p>
  
  <pre><code>Wrong number of args (1) passed to: blabla
  </code></pre>
  
  <h1>A simpler example.</h1>
  
  <p>I have a lot of java arrays. I do not want to use aget. I want macro to expand to <code>(aget array-name i)</code>. I write a macro that expand to <code>(fn [n] (aget array-name i))</code>, but this is unnecessary overhead.</p>
  
  <pre><code>(defmacro series [arr]
    `(fn [i#]
       (aget (longs ~arr) (int i#))))
  </code></pre>
  
  <p>I now declare the series, such as "date", and call it in this way <code>(date i)</code>, which will return me "i" element of the array. </p>