这并不完美,但它开始于编写def+
https://clojuredocs.org/clojure.core/destructure
(defmacro def+
"binding => binding-form
internalizes binding-forms as if by def."
{:added "1.9", :special-form true, :forms '[(def+ [bindings*])]}
[& bindings]
(let [bings (partition 2 (destructure bindings))]
(sequence cat
['(do)
(map (fn [[var value]] `(def ~var ~value)) bings)
[(mapv (fn [[var _]] (str var)) bings)]])))
有了它,你可以做...
(def+ [u s v] [1 5 9], foo "bar")
...同时不影响def
...的简单性
(def+ foo "bar")
...这是要求和建议的。这仍然存在将 gensym 变量引入全局命名空间的问题。可以处理 gensym 问题,但考虑到用例(在 repl 中使用),附加变量可能是可以接受的。