-
-
Save minikomi/b6e5a097970513934faf46f01f194725 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro let-stop [bindings & body] | |
(if (some #{'*stop*} bindings) | |
(let [stopped-bindings | |
(->> bindings | |
(take-while #(not= '*stop* %)) | |
vec) | |
caught-symbols | |
(->> 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 | |
*stop* | |
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