Deutsch   English   Français   Italiano  
<vavukd$150iv$1@dont-email.me>

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: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Translating circular Haskell code to lisp
Date: Sat, 31 Aug 2024 20:32:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <vavukd$150iv$1@dont-email.me>
References: <vasuce$iv6j$1@dont-email.me>
Injection-Date: Sat, 31 Aug 2024 22:32:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="becbf8d70a038bf1db72383f6d2892a4";
	logging-data="1213023"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18LWF1ToY3pPrXFKvmYygxX"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:eAOzEBUSsVaq/RtYSKfGUlmfsRU=
Bytes: 1762

B. Pym wrote:

> 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)

Since it's "cute" instead of "cut", (/ sum len) is done only once.

"Cute is a variation of cut that evaluates expr-or-slots before
creating the procedure."