Deutsch   English   Français   Italiano  
<20240809162102.706@kylheku.com>

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

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
Date: Fri, 9 Aug 2024 23:30:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <20240809162102.706@kylheku.com>
References: <v4lq9k$3t78r$1@dont-email.me> <87h6bttlo9.fsf@gmail.com>
Injection-Date: Sat, 10 Aug 2024 01:30:54 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="55856fbef320f8e8129676162efccf12";
	logging-data="255267"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Xd9/ppv5bwCT5mKSRUgqcuN2LfEcdh10="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:RoA9OEn3sO7gz8syWbTj5H+mBo0=
Bytes: 1661

On 2024-08-09, steve g <sgonedes1977@gmail.com> wrote:
> "B. Pym" <No_spamming@noWhere_7073.org> writes:
>
>< >     (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
>
>
> (loop for x in '(1 2 3 4 5)
>    summing x into max
>    counting x into cnt
>   finally (pprint (/ max cnt)))

2> [[callf / sum len] '(1 2 3 4 5)]
3.0