照应宏是一种引入变量(通常为IT)的宏,该变量捕获用户提供的表单的结果。一个常见的示例是Anaphoric If,它与regular一样IF,但也定义了变量IT以引用测试表单的结果。
(defmacro aif (test-form then-form &optional else-form) `(let ((it ,test-form)) (if it ,then-form ,else-form))) (defun test (property plist) (aif (getf plist property) (format t "The value of ~s is ~a.~%" property it) (format t "~s wasn't in ~s!~%" property plist))) (test :a '(:a 10 :b 20 :c 30)) ; The value of :A is 10. (test :d '(:a 10 :b 20 :c 30)) ; :D wasn't in (:A 10 :B 20 :C 30)!