我正在尝试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
答案 0 :(得分:3)
完全编译错误
(DEFUN IFELSE (THE-TEST)
(COND ((THE-TEST) ...
您的代码不同:
(defun ifelse (the-test)
(cond (the-test ...
您可能在测试期间更改了代码。
在实际代码中,您使用变量 the-test
在编译器错误中,函数试图调用函数(the-test)