-1

我在 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
4

1 回答 1

3

从完整的编译器错误

(DEFUN IFELSE (THE-TEST)
 (COND ((THE-TEST) ...

您的代码不同:

(defun ifelse (the-test)
  (cond (the-test ...

您可能在测试期间更改了代码。

在您的实际代码中,您使用变量the-test

在编译器错误中,函数试图调用函数(测试)

于 2013-11-01T07:19:26.263 回答