我在 CL 中尝试了一些基本的东西,但不明白为什么这不会编译:
(defun ifelse (the-test)
(cond ((the-test) (format t "passed test"))
(t (format t "failed test"))))
编译器说:
; caught STYLE-WARNING:
; undefined function: THE-TEST
我做了类似的事情if
没有麻烦:
(defun test-if (the-test)
(if the-test
(format t "passed")
(format t "failed")))
编译器不会抱怨。cond
因为他们都在测试一个条件,所以不会以同样的方式工作吗?
; in: DEFUN IFELSE
; (DEFUN IFELSE (THE-TEST)
; (COND ((THE-TEST) (FORMAT T "passed test, true!"))
; (T (FORMAT T "failed test, boo hoo"))))
; --> PROGN EVAL-WHEN
; ==>
; (SB-IMPL::%DEFUN 'IFELSE
; (SB-INT:NAMED-LAMBDA IFELSE
; (THE-TEST)
; (BLOCK IFELSE (COND (# #) (T #))))
; NIL 'NIL (SB-C:SOURCE-LOCATION))
;
; caught STYLE-WARNING:
; The variable THE-TEST is defined but never used.
; (THE-TEST)
;
; caught STYLE-WARNING:
; undefined function: THE-TEST
;
; compilation unit finished
; Undefined function:
; THE-TEST
; caught 2 STYLE-WARNING conditions