List 将变量值列表添加到Lisp中的列表
这是我的第一篇帖子,所以如果我太含糊或者没有正确地完成,我道歉 所以我有一个空列表L1和两个变量x和y,它们可以是任何东西 比如说x=10,y=20 我希望列表L1以x开头,然后我有一个WHEN循环,每次循环时它都会将y添加到列表中,但我似乎无法获得我想要的格式的列表 我目前有:List 将变量值列表添加到Lisp中的列表,list,lisp,append,common-lisp,List,Lisp,Append,Common Lisp,这是我的第一篇帖子,所以如果我太含糊或者没有正确地完成,我道歉 所以我有一个空列表L1和两个变量x和y,它们可以是任何东西 比如说x=10,y=20 我希望列表L1以x开头,然后我有一个WHEN循环,每次循环时它都会将y添加到列表中,但我似乎无法获得我想要的格式的列表 我目前有: (let ((L1 x))) ; Adds x to the list (loop (when (> n 10) (return)) ; While n <
(let ((L1 x))) ; Adds x to the list
(loop
(when (> n 10) (return)) ; While n < 10, add's y to the list.
(setq L1 (list L1 y))
(incf n)))
然而,我希望它能返回:
( (10) (20) )
( (10) (20) (20) )
( (10) (20) (20) (20) )
( (10) (20) (20) (20) (20) )
( (10) (20) (20) (20) (20) (20) ) ...
你知道我该怎么做吗
任何帮助都将不胜感激 例如:
(defun test ()
(let ((x 10) (y 20) (n 10))
(cons (list x)
(loop
for i from 1 to n
collect (list y)))))
然后
或
好的,太好了,谢谢!如何将第一个示例中的列表设置为L1?
(setq L1(test))
或(setq L1(cons(list x)…)
。
(defun test ()
(let ((x 10) (y 20) (n 10))
(cons (list x)
(loop
for i from 1 to n
collect (list y)))))
(test)
=> ((10) (20) (20) (20) (20) (20) (20) (20) (20) (20) (20))
(defun test ()
(let ((x 10) (y 20) (n 10))
(cons (list x) (make-list n :initial-element (list y)))))