Skip to content

Instantly share code, notes, and snippets.

@knjname
Last active December 13, 2015 21:39
Show Gist options
  • Select an option

  • Save knjname/4979068 to your computer and use it in GitHub Desktop.

Select an option

Save knjname/4979068 to your computer and use it in GitHub Desktop.
(defmacro if-let (binding-form when-true when-false)
(destructuring-bind (var-name var-expr) binding-form
`(let ((,var-name ,var-expr))
(if ,var-name
,when-true
,when-false))))
(macroexpand '(if-let (a 3)
a
(+ a a))) ; => (let ((a 3)) (if a a (+ a a)))
(if-let (a 3)
a
(+ a a)) ; => 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment