我正在通过Practical Common Lisp阅读/工作.我在关于在Lisp中构建测试框架的章节.
我的功能"test- +"实现如下,它的工作原理如下:
(defun test-+ ()
(check
(= (+ 1 2) 3)
(= (+ 5 6) 11)
(= (+ -1 -6) -7)))
Run Code Online (Sandbox Code Playgroud)
记住,我说,它有效,这就是为什么接下来是如此令人费解......
以下是"test- +"所指的一些代码:
(defmacro check (&body forms)
`(combine-results
,@(loop for f in forms collect `(report-result ,f ',f))))
(defmacro combine-results (&body forms)
(with-gensyms (result)
`(let ((,result t))
,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
,result)))
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body)) …Run Code Online (Sandbox Code Playgroud)