common-lisp 照应宏
示例
照应宏是一种引入变量(通常为IT)的宏,该变量捕获用户提供的表单的结果。一个常见的示例是AnaphoricIf,它与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)!
热门推荐
10 孩子出院上班祝福语简短
11 律所年会祝福语简短
12 广东考试祝福语朋友简短
13 写夏至的祝福语简短
14 新房落成的简短祝福语
15 高考同学留言祝福语简短
16 有趣虎年新春祝福语简短
17 年后同事聚餐祝福语简短
18 送媳妇首饰祝福语简短