Skip to content

Instantly share code, notes, and snippets.

@minikomi
Last active December 8, 2017 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minikomi/b6e5a097970513934faf46f01f194725 to your computer and use it in GitHub Desktop.
Save minikomi/b6e5a097970513934faf46f01f194725 to your computer and use it in GitHub Desktop.
(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