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

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

Path: ...!weretis.net!feeder9.news.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 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=
Bytes: 1813

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