Plaster

common-lisp
(defun call-with-handler (thunk condition-type handler) (funcall (compile nil `(lambda () (handler-bind ((,condition-type ,handler)) (funcall ,thunk)))))) (defun call-with-restart (thunk restart-name restart-function &key interactive-function test-function report-function) (funcall (compile nil `(lambda () (restart-bind ((,restart-name ,restart-function ,@(when interactive-function `(:interactive-function ,interactive-function)) ,@(when report-function `(:report-function ,report-function)) ,@(when test-function `(:test-function ,test-function)))) (funcall ,thunk)))))) CL-USER> (block foo (call-with-handler (lambda () (error "bar")) 'error (lambda (c) (return-from foo c)))) #<SIMPLE-ERROR "bar" {1003076FB3}> CL-USER> (block foo (call-with-restart (lambda () (invoke-restart 'frob)) 'frob (lambda () (return-from foo)))) NIL