(defmacro gen-plan
"Allows a user to define a state monad binding plan.
(gen-plan
[_ (assoc-in-plan [:foo :bar] 42)
val (get-in-plan [:foo :bar])]
val)"
[binds id-expr]
(let [binds (partition 2 binds)
psym (gensym "plan_")
forms (reduce
(fn [acc [id expr]]
(concat acc `[[~id ~psym] (~expr ~psym)]))
[]
binds)]
`(fn [~psym]
(let [~@forms]
[~id-expr ~psym]))))