defn

Help me write a Clojure macro which automatically adds metadata to a function definition

天涯浪子 提交于 2019-12-20 17:29:56
问题 I realize that the first rule of Macro Club is Don't Use Macros, so the following question is intended more as an exercise in learning Clojure than anything else (I realize this isn't necessarily the best use of macros). I want to write a simple macro which acts as a wrapper around a regular (defn) macro and winds up adding some metadata to the defined function. So I'd like to have something like this: (defn-plus f [x] (inc x)) ...expand out to something like this: (defn #^{:special-metadata

Help me write a Clojure macro which automatically adds metadata to a function definition

人走茶凉 提交于 2019-12-03 04:52:51
I realize that the first rule of Macro Club is Don't Use Macros, so the following question is intended more as an exercise in learning Clojure than anything else (I realize this isn't necessarily the best use of macros). I want to write a simple macro which acts as a wrapper around a regular (defn) macro and winds up adding some metadata to the defined function. So I'd like to have something like this: (defn-plus f [x] (inc x)) ...expand out to something like this: (defn #^{:special-metadata :fixed-value} f [x] (inc x)) In principle this doesn't seem that hard to me, but I'm having trouble