Skip to content

Instantly share code, notes, and snippets.

@astrangeguy
Created April 3, 2010 23:55
Show Gist options
  • Save astrangeguy/354955 to your computer and use it in GitHub Desktop.
Save astrangeguy/354955 to your computer and use it in GitHub Desktop.
(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