Deutsch   English   Français   Italiano  
<v8r51a$v47e$1@dont-email.me>

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

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
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=
Bytes: 2087

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)