Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connectionsPath: ...!news.nobody.at!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,comp.lang.scheme
Subject: Re: Translating circular Haskell code to lisp
Date: Fri, 30 Aug 2024 17:32:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <20240830101143.424@kylheku.com>
References:
Injection-Date: Fri, 30 Aug 2024 19:32:35 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cbe2877523f20dda3b599fd18e2277a3";
logging-data="622811"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18H2u0Ai7iApixht+W5HRJ7RhN891Qe82U="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:qgyROFSZOHf3mIYi575DnAp5Euw=
Bytes: 2195
On 2024-08-30, 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)))
The loop algorithm contains no explicitly visible side effects
whereas yours has ugly variable stepping.
Point-free one-liner:
This is the TXR Lisp interactive listener of TXR 296.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
TXR kind of supports IEEE 754.00000000000003 floating-point.
1> [[callf mapcar [chain [callf / sum len] (do op - @@1)] identity] '(1
2 3 4 5)]
(2.0 1.0 0.0 -1.0 -2.0)
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca