回指巨集
一個回指巨集是引入了捕獲使用者提供的形式的結果的變數(通常 IT
)的巨集。一個常見的例子是 Anaphoric If,它類似於常規的 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)!