Skip to content

Instantly share code, notes, and snippets.

@minikomi
Last active November 29, 2021 02:58
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/6bc7df405704ad6773ecc9dc2ad5fc04 to your computer and use it in GitHub Desktop.
Save minikomi/6bc7df405704ad6773ecc9dc2ad5fc04 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 (str (first %))) (first %)))
(into {}))]
`(let ~stopped-bindings
~caught-symbols))
`(let* ~(destructure bindings) ~@body)))
(let-stop
[a 1
b (* a 10)
c {:a a :b b}
*stop*
]
(+ a b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment