(defvar *restart-table* (make-hash-table :test 'eq)) (defun make-simple-restart-function (name report) (compile nil `(lambda (thunk restart-invoked-fn) (multiple-value-bind (value restart-taken) (with-simple-restart (,name ,report) (funcall thunk)) (if restart-taken (funcall restart-invoked-fn) value))))) (defun declare-simple-restart (name report) (check-type name symbol) (check-type report string) (setf (gethash name *restart-table*) (make-simple-restart-function name report))) (defun call-with-simple-restart (name function &optional restart-invoked-fn) (let ((restart-function (gethash name *restart-table*))) (unless restart-function (error "Restart ~S not declared." name)) (funcall restart-function function (or restart-invoked-fn (lambda () nil))))) ;;;; In the code (declare-simple-restart 'skip "Skip this item.") (call-with-simple-restart 'skip (lambda () (invoke-restart 'skip)) (lambda () 'skipped)) => SKIPPED