List 在公共Lisp中将列表压缩在一起-问题是;及;

List 在公共Lisp中将列表压缩在一起-问题是;及;,list,function,macros,common-lisp,List,Function,Macros,Common Lisp,我想做的是创建一个函数zip(注意,这不是家庭作业),它可以同时迭代多个列表,将一个函数应用于每个元素列表,如下所示: (zip f '(1 2 3) '(4 5 6) '(7 8 9)) = (list (f 1 4 7) (f 2 5 8) (f 3 6 9)) (zip f '(1 2 3 4) '(5 6) '(7 8 9)) = (list (f 1 5 7) (f 2 6 8)) 基本上,当任何列表的元素用完时,它就会停止。以下是我目前的尝试: (defun zip (f &

我想做的是创建一个函数
zip
(注意,这不是家庭作业),它可以同时迭代多个列表,将一个函数应用于每个元素列表,如下所示:

(zip f '(1 2 3) '(4 5 6) '(7 8 9)) = (list (f 1 4 7) (f 2 5 8) (f 3 6 9))
(zip f '(1 2 3 4) '(5 6) '(7 8 9)) = (list (f 1 5 7) (f 2 6 8))
基本上,当任何列表的元素用完时,它就会停止。以下是我目前的尝试:

(defun zip (f &rest lists)
  (if (apply and lists) ; <- Here is where I think the problem is.
    (cons (apply f (mapcar #'car lists)) (zip f &rest (mapcar #'cdr lists)))
    nil))
(取消压缩(f&rest列表)

(如果(应用并列出);您正在实现
mapcar

? (mapcar #'list '(1 2 3) '(4 5 6) '(7 8 9))
((1 4 7) (2 5 8) (3 6 9))
? (mapcar #'list '(1 2 3 4) '(5 6) '(7 8 9))
((1 5 7) (2 6 8))
? (mapcar #'+ '(1 2 3) '(4 5 6) '(7 8 9))
(12 15 18)
? (mapcar #'+ '(1 2 3 4) '(5 6) '(7 8 9))
(13 16)

顺便说一句,你想要在你的代码中取代
all
的功能是

谢谢!我不知道
mapcar
可以做到这一点!所有
all
都是偶然的。现在我能做些什么来修复这个条件?(应用#和列表);并将其余的从第二个arg到cons@DougCurrie:
根据clisp不是一个函数。而且,我现在意识到
cons
的第二个参数应该是(应用zip f(mapcar#'cdr列表))。我需要将新列表作为单个参数传递。有几个选项:(notany#'endp列表)或(每个#的身份列表)浮现在脑海中。