(defmacro def+
"def with binding (def+ [{:keys [a b d]} {:a 1 :b 2 :d 3}])"
[bindings]
(let [let-expr (macroexpand `(let ~bindings))
vars (filter #(not (.contains (str %) "__"))
(map first (partition 2 (second let-expr))))
def-vars (map (fn [v] `(def ~v ~v)) vars)]
(concat let-expr def-vars)))
;Example usage:
(def+ [a 1 b 2])
(def+ [{:keys [a b]} {:a 1 :b 2}])
(def+ [z 1
{:keys [a b]} {:a 1 :b 2}])
This should not be used in the final code - though it will work - but probably using in REPL is a better use for this macro.
