这是关于函数define中的变量绑定的问题:
如果我像这样定义funcion"total",则"total"中的x将绑定到let中的本地x.
CL-USER> (let ((x 0))
(defun total (y)
(incf x y)))
TOTAL
CL-USER> (defvar x 10000)
X
CL-USER> (total 1)
1
Run Code Online (Sandbox Code Playgroud)
但是,如果我像这样定义"total",x将在defvar中绑定到global x:
CL-USER> (defvar x 10000)
X
CL-USER> (let ((x 0))
(defun total (y)
(incf x y)))
TOTAL
CL-USER> (total 1)
10001
Run Code Online (Sandbox Code Playgroud)
为什么这个?我需要一个解释来理解它.环境是windows + emacs + slime + sbcl.Thanks.