Skip to content

Instantly share code, notes, and snippets.

@sjl
Created October 12, 2016 18:06
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 sjl/ae5c5813f1fa34ec0b5b5c7bb692883e to your computer and use it in GitHub Desktop.
Save sjl/ae5c5813f1fa34ec0b5b5c7bb692883e to your computer and use it in GitHub Desktop.
(defmacro let-bail (bindings &rest body)
(if (null bindings)
`(progn ,@body)
(destructuring-bind ((&whole binding symbol value &optional return-value)
&rest more-bindings)
bindings
(if (eql symbol 'bail-when)
`(if ,value ,return-value (let-bail ,more-bindings ,@body))
`(let (,binding) (let-bail ,more-bindings ,@body))))))
(let-bail ((x (random 100))
(bail-when (oddp x) 'what)
(y (1+ x)))
(list x y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment