如何在common-lisp中每次从列表中获取两个元素?

时间:2012-02-16 11:59:31

标签: lisp common-lisp

对于((1 2) (3 4) (5 6)),您可以使用loop for (a b) in '((1 2) (3 4) (5 6))每次获得a = 1,b = 2。

但对于'(1 2 3 4),我尝试loop for x on '(1 2 3 4) by #'cddr for a = (car x) for b = (cadr x)得到a = 1,b = 2.

有没有更好的方法来做这件事?

1 个答案:

答案 0 :(得分:7)

尝试for ... on

(loop for (a b) on '(1 2 3 4) by #'cddr collect (cons a b))