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

Isa*_*acS 1 clisp sbcl common-lisp

加载以下2个功能clisp成功.

(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)  
)
Run Code Online (Sandbox Code Playgroud)

但是,sbcl导致错误:

warning: undefined variable: COUNT
warning: undefined variable: RESLIS
Compilation failed.
Run Code Online (Sandbox Code Playgroud)

我更喜欢使用sbcl(因为我slime唯一的用途),但上面的代码有什么问题?

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

Rai*_*wig 9

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

怎么了?

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

  • count简直是未定义的.正如SBCL所说.你无处count定义变量.