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

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

Path: ...!2.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" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Translating circular Haskell code to lisp
Date: Fri, 30 Aug 2024 17:09:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <vasuce$iv6j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 30 Aug 2024 19:09:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7471b6bf57a1160866342d87b5967bc4";
	logging-data="621779"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18CyvKUQlu++jk+R2t2DB13"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:wuFJuYUAStznLAtZD11xCMhdqRQ=
Bytes: 1589

Pascal Costanza wrote:

> > I don't need a general purpose transformation, just some guidelines to
> > follow when I see code like this.
> 
> General guideline: Look for a solution that uses LOOP. ;)
> 
> (defun diff3 (list)
>    (let ((avg (loop for element in list
>                     sum element into sum
>                     count t into length
>                     finally (return (/ sum length)))))
>      (loop for element in list
>            collect (- element avg))))

Gauche Scheme

(define (diff3 lst)
  (let ((len 0) (sum 0))
    (dolist (x lst) (inc! len) (inc! sum x))
    (map (cute  - <> (/ sum len)) lst)))

(diff3 '(1 2 3 4 5))
  ===>
(-2 -1 0 1 2)