| Deutsch English Français Italiano |
|
<87h6bttlo9.fsf@gmail.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!local-3.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 09 Aug 2024 21:45:47 +0000 From: steve g <sgonedes1977@gmail.com> Newsgroups: comp.lang.lisp Subject: Re: Finding Average without using Recusrion only using Prog References: <v4lq9k$3t78r$1@dont-email.me> Date: Fri, 09 Aug 2024 17:45:42 -0400 Message-ID: <87h6bttlo9.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:k4E5EJQtUB/SEThdaBgxpgZZWEk= MIME-Version: 1.0 Content-Type: text/plain Lines: 35 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-ccQmPCShllBc/UVW8dYbwCyOPb0Y06CH7rwSPzVFXlmhqsKHzLpcb2cc59git7yqvTvzsbFBzHc3hHz!W7mX7GR7bWIM0q7x+kU13cgzU8bhCzYYYB05y71/N31e8F0= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Bytes: 1642 "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)))