小编Vij*_*nna的帖子

LET和SETQ之间的区别?

我正在使用GCL在Ubuntu上编程.从各种来源的Common Lisp文档中,我了解到let创建局部变量,并setq设置现有变量的值.在下面的例子中,我需要创建两个变量并对它们的值求和.

运用 setq

(defun add_using_setq ()
  (setq a 3)  ; a never existed before , but still I'm able to assign value, what is its scope?
  (setq b 4)  ; b never existed before, but still I'm able to assign value, what is its scope?
  (+ a b))
Run Code Online (Sandbox Code Playgroud)

运用 let

(defun add_using_let ( )
  (let ((x 3) (y 4)) ; creating variables x and y
     (+ x y)))
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,我似乎都取得了相同的结果; 使用setq …

lisp common-lisp

22
推荐指数
2
解决办法
1万
查看次数

标签 统计

common-lisp ×1

lisp ×1