Created
April 3, 2010 23:55
-
-
Save astrangeguy/354955 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
(defn label* [thunk] | |
(let [NONE (Object.) | |
payload (clojure.lang.Box. NONE) | |
the-e (Exception.)] | |
(try | |
(thunk (fn [ret] | |
(if (identical? NONE (.val payload)) | |
(do (set! (.val payload) ret) | |
(throw the-e)) | |
(throw (Exception. "Tried to jump outside extent."))))) | |
(catch Exception e | |
(if (identical? the-e e) | |
(.val payload) | |
(throw e))) | |
(finally (set! (.val payload) nil))))) | |
(defmacro label [name & body] | |
`(label* (fn [~name] ~@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment