Sujet : Re: When to use apply
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 17. Jun 2025, 16:33:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102s1s5$2fmdi$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
B. Pym wrote:
Of course, after going through all of that you then see why loop is so
handy:
CL-USER> (defun nth-elements (n &rest lists)
(loop for item in lists collect (nth n item)))
NTH-ELEMENTS
CL-USER> (nth-elements 3 '(10 20 hello x world) '(-1 -2 -3 y) '(z0 z1 z2 z))
(X Y Z)
(define (nth-elements n . seqs)
(map (lambda (xs) (list-ref xs n)) seqs))
(nth-elements 3
'(10 20 hello x world)
'(-1 -2 -3 y)
'(z0 z1 z2 z))
===>
(x y z)
Shorter:
(define (nth-elements n . seqs)
(map (cut list-ref <> n) seqs))