我将自己设置为编写Common Lisp函数的任务,该函数在不使用append的情况下连接两个列表。
Common Lisp输入(concat-lists’(1 2 3)’(4 5 6))应返回(1 2 3 4 5 6)
即使 …
我确实理解你对'减少'的要求。还有其他选择:
CL也有'concatenante'
(concatenate 'list '(1 2 3) '(4 5 6))
还有其他不那么复杂的(恕我直言),而不是那么优雅。
(defun concat-lists (list1 list2) (let ((a (copy-list list1)) (b (copy-list list2))) (rplacd (last a) b) a))
要么
(defun concat-lists (list1 list2) (let ((a (copy-list list1)) (b (copy-list list2))) (nconc a b)))
CL-USER 39 > (reduce #'cons '(1 2 3 4 5) :initial-value '(a b c d e) :from-end t) (1 2 3 4 5 A B C D E)