Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Do molecular biologists wear designer genes?


devel / comp.lang.lisp / .Re: When to use apply

SubjectAuthor
o .Re: When to use applyRobert L.

1
.Re: When to use apply

<t0k71u$i5n$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16956&group=comp.lang.lisp#16956

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!W3tGPiuqVkNEMj0crCqmNQ.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: When to use apply
Date: Sun, 13 Mar 2022 07:38:41 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t0k71u$i5n$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="18615"; posting-host="W3tGPiuqVkNEMj0crCqmNQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Sun, 13 Mar 2022 07:38 UTC

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

Instead of CL, let's use a Lisp.

Gauche Scheme and Racket:

(define (nth-elements n . seqs)
(map (& list-ref u n) seqs))

(nth-elements 3
'(10 20 hello x world)
'(-1 -2 -3 y)
'(z0 z1 z2 z))

===>
(x y z)

Given:

(define-syntax &-aux
(syntax-rules (u v w & lambda quote)
[(_ () shadow (param ...) original)
(lambda (param ...) original)]
[(_ (u more ...) (x y ...) () original)
(&-aux original original (x) original)]
[(_ (v more ...) (x y ...) (a) original)
(&-aux original original (a x) original)]
[(_ (w more ...) (x y ...) (a b) original)
(&-aux () () (a b x) original)]
[(_ ((lambda x ...) more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]
[(_ ((& x ...) more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]
[(_ ((quote x ...) more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]
[(_ ('x more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]
[(_ ((s ...) more ...) (y z ...) params original)
(&-aux (s ... more ...) (s ... z ...) params original)]
[(_ (x more ...) (y z ...) params original)
(&-aux (more ...) (z ...) params original)]))
;; Lambda with anaphoric parameters u, v, and w.
(define-syntax &
(syntax-rules ()
[(& x ...)
(&-aux (x ...) (x ...) () (x ...))]))


devel / comp.lang.lisp / .Re: When to use apply

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor