Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

So you're back... about time...


comp / comp.lang.lisp / Re: MAP (and variants) vs LOOP - Popular opinion observation?

SubjectAuthor
* Re: MAP (and variants) vs LOOP - Popular opinion observation?B. Pym
`- Re: MAP (and variants) vs LOOP - Popular opinion observation?B. Pym

1
Subject: Re: MAP (and variants) vs LOOP - Popular opinion observation?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sun, 8 Sep 2024 12:06 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: MAP (and variants) vs LOOP - Popular opinion observation?
Date: Sun, 8 Sep 2024 12:06:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <vbk3vn$1tpt1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 08 Sep 2024 14:06:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ca987dadbaef2aac0a61f448ffc30def";
logging-data="2025377"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BTXOTTfZGc9m4gjp1nRdS"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:L6F2otge8oyfxW9n5YkaJFZTWCU=
View all headers

> Then suppose you later need the loop/map to collect some of the values
> under certain conditions. You might have
>
> (loop for x in (get-list)
> for i from 0
> do (format t "~A - ~A~%" i x)
> if (test x)
> collect (foo x))

Gauche Scheme

(use srfi-13) ;; string-upcase

(filter-map
(lambda (x i) (print i " - " x)
(and (string? x) (string-upcase x)))
'(foo "an" 8 "why")
(lrange 0))

0 - foo
1 - an
2 - 8
3 - why
("AN" "WHY")

Subject: Re: MAP (and variants) vs LOOP - Popular opinion observation?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sun, 8 Sep 2024 12:44 UTC
References: 1
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: MAP (and variants) vs LOOP - Popular opinion observation?
Date: Sun, 8 Sep 2024 12:44:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <vbk67q$1u3dp$1@dont-email.me>
References: <vbk3vn$1tpt1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 08 Sep 2024 14:44:45 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ca987dadbaef2aac0a61f448ffc30def";
logging-data="2035129"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fO3U43fvFnvgbXsQBlomE"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:mOAWIdA+dawrGSrTbkrmb/8l0y0=
View all headers

B. Pym wrote:

> > Then suppose you later need the loop/map to collect some of the values
> > under certain conditions. You might have
> >
> > (loop for x in (get-list)
> > for i from 0
> > do (format t "~A - ~A~%" i x)
> > if (test x)
> > collect (foo x))
>
> Gauche Scheme
>
> (use srfi-13) ;; string-upcase
>
> (filter-map
> (lambda (x i) (print i " - " x)
> (and (string? x) (string-upcase x)))
> '(foo "an" 8 "why")
> (lrange 0))
>
> 0 - foo
> 1 - an
> 2 - 8
> 3 - why
> ("AN" "WHY")

> Suppose you have
>
> (loop for x in (get-list)
> do (format t "~A~%" x))
>
> and then it turns out you need to print a numeric index. You can do
>
> (loop for x in (get-list)
> for i from 0
> do (format t "~A - ~A~%" i x))
>
> If you start with
>
> (mapc (lambda (x) (format t "~A~%" x)) (get-list))
>
> it seems (to me) that it'd be harder to modify it as needed,
>
> (let ((list (get-list)))
> (mapc (lambda (i x) (format t "~A - ~A" i x))
> (range 0 (length list))
> list))
>
> (I'm assuming the toolkit includes a RANGE utility, or something similar.)

Gauche Scheme

Shorter than the loop:

(for-each
(pa$ format #t "~a - ~a\n")
(lrange 0)
'(a b c))

0 - a
1 - b
2 - c

1

rocksolid light 0.9.8
clearnet tor