Lisp 更改let函数中定义的变量
给定以下let函数:Lisp 更改let函数中定义的变量,lisp,let,Lisp,Let,给定以下let函数: (let ((foo (list a b c d))) foo) 如何修改列表foo (let ((foo (list a b c d))) ;some code foo) 因此,返回的foo看起来像eks:'(一些新列表)或(a b修改的d) 我尝试过(设置),但foo仍将作为原始列表返回。您可以使用setf修改列表中的特定元素 (let ((foo (list 'a 'b 'c 'd))) (setf (third foo) 'modified) foo)
(let ((foo (list a b c d)))
foo)
如何修改列表foo
(let ((foo (list a b c d)))
;some code
foo)
因此,返回的foo看起来像eks:'(一些新列表)或(a b修改的d)
我尝试过(设置),但foo仍将作为原始列表返回。您可以使用
setf
修改列表中的特定元素
(let ((foo (list 'a 'b 'c 'd)))
(setf (third foo) 'modified)
foo)
这将返回(a b modified d)
或者,如果要替换整个变量,可以使用setq
直接为其赋值:
(let ((foo (list 'a 'b 'c 'd)))
(setq foo (list 'some 'new 'list))
foo)
不能对词法变量使用
set
,只能使用特殊变量。可以使用setf
修改列表中的特定元素
(let ((foo (list 'a 'b 'c 'd)))
(setf (third foo) 'modified)
foo)
这将返回(a b modified d)
或者,如果要替换整个变量,可以使用setq
直接为其赋值:
(let ((foo (list 'a 'b 'c 'd)))
(setq foo (list 'some 'new 'list))
foo)
不能对词法变量使用set
,只能使用特殊变量