Rudolf Adamkovič Personal site


My with-early-exit macro

Inspired by call-with-current-continuation in Scheme.

(macro with-early-exit [[out] body]
  "Execute BODY, exiting early with `...' on (OUT ...)."
  `(let [sentinel# {}]
     (λ ,out [...]
       (error [sentinel# ...] 2))
     (match (pcall #,body)
       (true result#) result#
       (false [sentinel# & rest#]) (table.unpack rest#)
       (false other#) (error other# 2))))

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.