Skip to content

Instantly share code, notes, and snippets.

@hyotang666
Created April 18, 2018 17:29
Show Gist options
  • Save hyotang666/4469845cf8e6c52eb4b2a0492397e340 to your computer and use it in GitHub Desktop.
Save hyotang666/4469845cf8e6c52eb4b2a0492397e340 to your computer and use it in GitHub Desktop.
#++
(defun foo()
(with-guards((print "fle closed!!!")
(print "pipe closed!!!")
(print "socket closed!!!"))
(print "using")))
(defmacro with-guards((&rest guard*)&body body)
(labels((rec(guard*)
(if(endp guard*)
(cons 'progn body)
`(unwind-protect ,(rec(cdr guard*))
,(car guard*)))))
(rec guard*)))
#| in REPL.
* (foo)
"using"
"socket closed!!!"
"pipe closed!!!"
"fle closed!!!"
"using" ; <--- return value.
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment