Clojure macro as a function / "Partial" for macros?

This seems like the issue discussed in the Clojure Wizard as a function , but when I tried to approach in the top answer, I got an error. Hopefully too much information about my specific application is not needed because it is rather complicated, but here is a distilled version of what I was trying to do:

(defmacro make-fn [m arg1] 
    `(fn [& args#] 
      (eval `(~'~m ~'~arg1 ~@args#))))

I used a macro in this context:

(let [columns (make-columns table-width)
       table-name (keyword (str "table_" n))]
  (apply (make-fn helpers/tbl table-name) columns))

"helpers / tbl" is a macro that expects a table keyword and a variable number of lists containing column specifications (for example, [: varchar 100] or something else). I am trying to create database table specifications on the fly to facilitate some tests. Anyway, when I try to execute the above code, I get the following error:

CompilerException java.lang.RuntimeException: Unable to resolve symbol: table-name in this context, compiling:(NO_SOURCE_PATH:1) 

: , , , , . , . ?

+5
1

, Clojure - ( ). , Clojure , Vars ( locals).

" " , , . , , ... , :

(defmacro make-fn [m arg1]
  (let [g (gensym)]
    (list 'fn ['& g]
      (list 'eval (list 'concat (list 'list m arg1) g)))))

, Lisp...

+2

All Articles