请考虑以下代码:
(define-condition some-condition (error) nil)
(defmethod print-object ((obj some-condition) stream)
(format stream "HELLO THERE"))
(defmacro error-report-test-aux (fn-to-cause-error error-type-to-catch fn-to-handle-error expected-message)
`(let ((result-message
(handler-case (funcall ,fn-to-cause-error)
(,error-type-to-catch (e) (funcall ,fn-to-handle-error e)))))
(assert (string= result-message
,expected-message))
t))
Run Code Online (Sandbox Code Playgroud)
我可以像这样使用它:
(error-report-test-aux (lambda () (error 'some-condition))
some-condition
#'princ-to-string
"HELLO THERE")
Run Code Online (Sandbox Code Playgroud)
但我想创建error-report-test-aux
一个函数而不是宏,这样我就可以在变量中传递一种条件.
简单地编写defun
代替defmacro
和删除反引号和逗号不起作用,因为handler-case
它是宏并且它不会评估error-type-to-catch
.
我的问题是:是否有类似的东西handler-case
会评估它的参数(特别是条件类型参数)?
common-lisp ×1