Deutsch   English   Français   Italiano  
<v4lq9k$3t78r$1@dont-email.me>

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

Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <No_spamming@noWhere_7073.org>
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
Date: Sun, 16 Jun 2024 04:39:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <v4lq9k$3t78r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 16 Jun 2024 06:39:19 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c83d270445aa4b2c39858211581a12ef";
	logging-data="4103451"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX197/THEOzhQ7c9W/KlnHdZ9"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:ybvIEiW8HSgONggV/lKa0qFZw80=
Bytes: 1322

>     (defun avg (args)
>       (loop for x in args
>           for l upfrom 1
>           summing x into tot
>           finally (return (/ tot l))))

Gauche Scheme

(use gauche.collection) ;; fold2

(define (add&count n sum cnt) (values (+ sum n) (+ cnt 1)))

(define (avg nums)
  (apply /
    (values->list
      (fold2
        add&count
        0 0
        nums))))

(avg '(20 30 40 50 60 70 80))
  ===>
50