sbcl上未定义的变量,而不是clisp上的变量



clisp上加载以下2个函数成功。

(defun func1 (l)
  (defvar *count* nil)
  (setq count 1)
  (cond ((null l) 0)
        ((atom l) (+ count 1))
        ((atom (car l)) (+ count (func1 (cdr l))))
        ((listp (car l)) (+ (func1 (car l)) (func1 (cdr l))))
        (t nil))    )
(defun func2 (l)
  (defvar *resLis* nil)
  (setq resLis '((0 0)))
  (anotherFunc l resLis)  
)

但是,sbcl导致错误:

warning: undefined variable: COUNT
warning: undefined variable: RESLIS
Compilation failed.

我更喜欢使用sbcl(因为我的slime只适合它),但上面的代码有什么问题?

环境:Ubuntu 11.10,GNU CLISP 2.49,SBCL 1.0.50.0.debian

SBCL不会"导致错误"。编译器打印警告。如果您使用CLISP的解释器而不是编译器,CLISP可能不会发出警告。SBCL默认使用编译器。

怎么了?

  • DEFVAR是定义全局变量的顶级形式。可以在函数中使用它,但不建议使用。

  • CCD_ 6只是未定义。正如SBCL所说。您没有定义变量count

首先,注意*count*count是两个不同的东西。*resLis*resLis也是如此。

第二,:func1中间做什么?

第三,anotherFunc在哪里?

第四,不要在函数中使用defvar;这些是给全球的!

一旦你解决了这些问题,你应该会发现它更容易开始。

最新更新