I am trying to define a macro like this:
(defmacro foo-macro
"[name] is the name of the function to define
[meta-data] is the map that defines the meta-data of the function"
[name meta-data]
(let [vals (gensym "label-")]
`(def ~name
^@~meta-data
(fn [~vals] (eval nil)))))
However, I am getting this compilation error:
Unhandled java.lang.IllegalArgumentException Metadata must be Symbol,Keyword,String or Map
I think this is normal. However, I am not sure how I can make such a macro to work, or if it is even possible.
Note: I do not want to use with-meta. Read the revision of the resolution of this other question to understand why: Clojure: issues getting the symbol of a function in a looping context.
The only reason why I would use with-meta, is if you have a way to make it return a non-AFunc identifier.
with-metainstead of^{}then I get#< clojure.lang.AFunction$1@15ab1764>as a reference for that object instead of something more human readable like#<core$foo user.core$foo@66e37466>. Even if the documentation says that there is no difference between these two methods, the difference appears to be that what is returned bywith-metais not the same as with the^{}macro (not the same object reference) - Neoasimov^{~meta-key ~meta-val}would work since themeta-dataparameter is a map itself (which is used to provide the meta-data to the function. What I need to do is to let people create a series of functions, but with a specific pattern. So I was using a macro to enforce that specific pattern to follow. My problem is that I let them define all the necessary meta-data using the map. However, I am thinking that I could use keyword parameters for the common and more static meta-data values, and then an optional meta-data parameter where they could add more if necessary. - Neoasimov