Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get two elements from a list each time in common-lisp?

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?

like image 866
Kane Avatar asked Oct 19 '25 07:10

Kane


1 Answers

Try for ... on:

(loop for (a b) on '(1 2 3 4) by #'cddr collect (cons a b))
like image 122
huaiyuan Avatar answered Oct 22 '25 04:10

huaiyuan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!