Sujet : Re: CL: Processing more than one element of a sequence at a time?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 19. Aug 2024, 03:50:18
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v9u8cp$2n5rr$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Frode V. Fjeld wrote:
Raffaele Ricciardi <rfflrccrd@gmail.com> writes:
in CL, is there an idiomatic way to process more than one element of a
sequence at a time?
Yes: (loop for (a b) on list by #'cddr collect (cons a b))
Or without LOOP, I'd do:
(do ((a (pop list) (pop list))
(b (pop list) (pop list))
(result nil))
((null list) (reverse result))
(push (cons a b) result))
newLISP
(apply
(fn (result a b) (push (cons a b) result -1))
(cons '() '(f 3 g 4 h 5))
3 ;; How many items to process at a time.
)
((f 3) (g 4) (h 5))