Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Beware of a tall blond man with one black shoe.


comp / comp.lang.lisp / Re: The LOOP macro

SubjectAuthor
* Re: The LOOP macroB. Pym
`- Re: The LOOP macroB. Pym

1
Subject: Re: The LOOP macro
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 5 Aug 2024 04:53 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
Subject: Re: The LOOP macro
Date: Mon, 5 Aug 2024 04:53:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <v8plr8$gnln$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 05 Aug 2024 06:53:01 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7494c0c807b5ee450e56fbedd80570a2";
logging-data="548535"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lYXGZT51hjjJquCpGkzoX"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:iU/U8DOSMDgMsHZdZx8zJ6FX2Xo=
View all headers

> > > Do you have a good example of LOOP's power / flexibility that doesn't
> > > need much surrounding context to understand?
> >
> > Here are a few:
> >
> > (loop repeat 100 collect (random 10))

newLISP

(collect (rand 10) 100)

> > (loop for x across array-of-numbers
> > minimizing x into min
> > maximizing x into max
> > summing x into total
> > counting t into count
> > finally (return (list min max (/ total count))))

(define array-of-numbers (array 9 '(2 -2 0 9 7 8 3 4 3)))

(local (mx mn total cnt)
(dolist (n array-of-numbers)
(setq mx (max (or mx n) n))
(setq mn (min (or mn n) n))
(++ total n)
(++ cnt))
(list mn mx (div total cnt)))

(-2 9 3.777777777777778)

Another way:

(list (apply min array-of-numbers)
(apply max array-of-numbers)
(div (apply + array-of-numbers) (length array-of-numbers)))

Subject: Re: The LOOP macro
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 5 Aug 2024 18:18 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
Subject: Re: The LOOP macro
Date: Mon, 5 Aug 2024 18:18:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <v8r51a$v47e$1@dont-email.me>
References: <v8plr8$gnln$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 05 Aug 2024 20:18:22 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4d0da7ed839683006bcf3d49bfd7bbbd";
logging-data="1020142"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kqHH3sbhN01qiDBrM13wD"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:/oVI1PDrlnhdStOvvi3AYqNsc+o=
View all headers

B. Pym wrote:

> > > > Do you have a good example of LOOP's power / flexibility that doesn't
> > > > need much surrounding context to understand?
> > >
> > > Here are a few:
> > >
> > > (loop repeat 100 collect (random 10))
>
>
> newLISP
>
> (collect (rand 10) 100)
>
>
>
> > > (loop for x across array-of-numbers
> > > minimizing x into min
> > > maximizing x into max
> > > summing x into total
> > > counting t into count
> > > finally (return (list min max (/ total count))))
>
>
> (define array-of-numbers (array 9 '(2 -2 0 9 7 8 3 4 3)))
>
> (local (mx mn total cnt)
> (dolist (n array-of-numbers)
> (setq mx (max (or mx n) n))
> (setq mn (min (or mn n) n))
> (++ total n)
> (++ cnt))
> (list mn mx (div total cnt)))
>
> (-2 9 3.777777777777778)
>
> Another way:
>
> (list (apply min array-of-numbers)
> (apply max array-of-numbers)
> (div (apply + array-of-numbers) (length array-of-numbers)))

Another way:

(list (apply min array-of-numbers)
(apply max array-of-numbers)
((stats array-of-numbers) 1))

(-2 9 3.777777777777778)

1

rocksolid light 0.9.8
clearnet tor