Skip to content

Instantly share code, notes, and snippets.


minikomi/stopping-let.clj Secret

Last active Dec 8, 2017
What would you like to do?
(defmacro let-stop [bindings & body]
(if (some #{'*stop*} bindings)
(let [stopped-bindings
(->> bindings
(take-while #(not= '*stop* %))
(->> stopped-bindings
(partition 2)
(map #(vector (keyword (first %)) (first %)))
(into {}))]
`(let ~stopped-bindings
(throw (ex-info (str "Let was stopped at stage "
(/ (count ~stopped-bindings) 2))
{:current-symbols ~caught-symbols}))))
`(let* ~(destructure bindings) ~@body)))
;; use
(let-stop [a 1
b 2
c 6
(println a b c))
#_> (ex-data *e)
{:current-symbols {:a 1, :b 2}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.