Common Lisp: what's the best way to loop through consecutive pairs in a list?

Viewed 3018

Sometimes I need to loop through consecutive pairs in a list. The way I do it right now is

(loop for x on lst while (not (null (cdr x)))
       (do something on (car x) and (cadr x)))

I'm wondering if there is a better/built-in way to do this.

The reason I need this is sometimes I want, e.g. some function that add consecutive pairs

(1 2 3 4 5) ----> (3 5 7 9)

Is there any built-in function like reduce which allow me to get this?

2 Answers
Related