Deutsch English Français Italiano |
<87bk21tldx.fsf@gmail.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!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:52:00 +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:51:54 -0400 Message-ID: <87bk21tldx.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:pOo319KG2ZNAJUplV2WZdOT6Jtc= MIME-Version: 1.0 Content-Type: text/plain Lines: 39 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-bPRw3NebCtN297twHP6T/DvcWuuM3+x9HouKzM0uiEGz97R1p6G/sz+tB1YBV/fB0O3vnlm19Y1Jwbl!v6FhrJ6YHXm+7/Wvgq2BCk2HNW51UflQyH+0+Y6AyKQw2Ig= 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: 1745 "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 (defun avg-with-prog (lst) (prog ((avg 0) (cnt 0)) START (setq avg (+ avg (pop lst))) (incf cnt) (if (endp lst) (GO END) (GO START)) END (print (/ avg cnt))))