Deutsch   English   Français   Italiano  
<102s1s5$2fmdi$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp
Subject: Re: When to use apply
Date: Tue, 17 Jun 2025 15:33:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <102s1s5$2fmdi$1@dont-email.me>
References: <102s1dt$2fj7t$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 17 Jun 2025 17:33:28 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="9ea469e93c951e8474b1305042a93325";
	logging-data="2611634"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19rXXgw+zoXdVZxc3jLZfWb"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:2x7lhAe46enO7lE1A8xGw3knNjw=

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))