Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #36: dynamic software linking table corrupted


comp / comp.lang.lisp / Re: What's more idiomatic?

SubjectAuthor
o Re: What's more idiomatic?B. Pym

1
Subject: Re: What's more idiomatic?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sun, 22 Sep 2024 08:38 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: What's more idiomatic?
Date: Sun, 22 Sep 2024 08:38:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <vcol2p$2565i$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 22 Sep 2024 10:38:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c82dcfe1e0fc09fa43073f78ca8be61c";
logging-data="2267314"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zNDQii7FQyk8NozRfKKNF"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:GVos5m9wXDG45/O9QGR56u7veZ4=
View all headers

Pascal Costanza wrote:

> (loop for x in '(1 2 3)
> for y in '(4 5 6)
> collect (* 2 (+ x y)))
>
> vs.
>
> (mapcar (lambda (x y)
> (* 2 (+ x y)))
> '(1 2 3)
> '(4 5 6))

However, what if there were 9 lists instead of 2?
The CL (COBOL-Like) version would become:

(loop for a in '(1 2 3)
for b in '(4 5 6)
for c in '(7 8 9)
for d in '(20 21 22)
for e in '(23 24 25)
for f in '(26 27 28)
for g in '(29 30 31)
for h in '(32 33 34)
for i in '(35 36 37)
collect (* 2 (+ a b c d e f g h i)))

===>
(354 372 390)

The Scheme version would simply become:

(map (~>> + (* 2))
'(1 2 3)
'(4 5 6)
'(7 8 9)
'(20 21 22)
'(23 24 25)
'(26 27 28)
'(29 30 31)
'(32 33 34)
'(35 36 37))

===>
(354 372 390)

Given:

(define-syntax ->>
(syntax-rules ()
[(_ x) x]
[(_ x (y ...) z ...)
(->> (y ... x) z ...)]
[(_ x y z ...)
(->> (y x) z ...)]))

(define-syntax ~>>
(syntax-rules ()
[(_ (func0 a ...) func ...)
(lambda xs (->> (apply func0 a ... xs) func ...))]
[(_ func0 func ...)
(lambda xs (->> (apply func0 xs) func ...))]))

1

rocksolid light 0.9.8
clearnet tor