Reputation: 898
For ((1 2) (3 4) (5 6))
, you can use loop for (a b) in '((1 2) (3 4) (5 6))
to get a = 1, b = 2 each time.
But for '(1 2 3 4)
, I try to do loop for x on '(1 2 3 4) by #'cddr for a = (car x) for b = (cadr x)
to get a = 1, b = 2.
Is there a better way to do such thing?
Upvotes: 4
Views: 1174
Reputation: 26549
Try for ... on
:
(loop for (a b) on '(1 2 3 4) by #'cddr collect (cons a b))
Upvotes: 10