From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.user Subject: Re: guile style Date: Sat, 19 Jun 2021 19:59:36 +0200 Message-ID: References: <7aeef132-6bd7-c178-5786-c0a3d6b3edc8@nycap.rr.com> <1e959322-f5f8-9bc3-ae08-a30165f9f409@nycap.rr.com> Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25801"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.5.0-alpha0-526-gf020ecf851-fm-20210616.001-gf020ecf8 Cc: guile-user To: jerry , "Christopher Lam" Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jun 19 20:00:35 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lufGk-0006Va-7R for guile-user@m.gmane-mx.org; Sat, 19 Jun 2021 20:00:35 +0200 Original-Received: from localhost ([::1]:39562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lufGj-0004l0-8q for guile-user@m.gmane-mx.org; Sat, 19 Jun 2021 14:00:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lufGK-0004kn-9P for guile-user@gnu.org; Sat, 19 Jun 2021 14:00:08 -0400 Original-Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:60879) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lufGH-000107-AT for guile-user@gnu.org; Sat, 19 Jun 2021 14:00:07 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 12038F8B; Sat, 19 Jun 2021 14:00:00 -0400 (EDT) Original-Received: from imap43 ([10.202.2.93]) by compute5.internal (MEProxy); Sat, 19 Jun 2021 14:00:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.se; h= mime-version:message-id:in-reply-to:references:date:from:to:cc :subject:content-type:content-transfer-encoding; s=fm3; bh=Js9dy v9Y4JUPCzMsyEsEx9M0mKD1oV1A35d77+uK2os=; b=LrUfo63j4GPwU2ilIk5sP mVfjTBe29I8sUimk/r84lRZk/3H+j8jMXCp9AIRpy469Z9jQc4hjgPsOYw+41iRU Ki5JsqHhoFedO8/IijqtHpV2KVITmIY7mqOzqIjOb0KB7k9CYyrDZ24IzbuV+BCx z0jTEP9puOXTMC1OgOijXtL65gEvIRGszN39QvOSjTC6qU51FmmySiSCiaSLIbU0 sxEOyMlUxz8rZr2Hr5srCtlVsDJ85aw3kHog8EP3s0bqSUgc+3HkKxdwp1IffEbQ T3uTX78M3eRgxBcyb7UhqWZGyYoTecEB/fmggr+vRy47DsnXJsXU7+ZMD/ZrP1Yi A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=Js9dyv9Y4JUPCzMsyEsEx9M0mKD1oV1A35d77+uK2 os=; b=kniHvSY5rDYLMaSn3eQJUA7cO+nN3VJjcPXnwX5rcRfLMupmPP89uacgk B0n1XkRufcpCmqZOBr3zq6rBsfBK6aAXK/QfD9VSP0PDlhFVBkQEZxKU1umQATAK bwhbKtw6wlgdrabOXDmt+F/rK1TC+qCjETKHwHDlOtOnmOrl4ZD/2orQUFsChFok odbBjEqrvRHMHMC4yOIHn28UIujawELMisw3nGMRJxUTRw1Df/UcHhSNY/FzOLOM 6DLZZwu5yfEsf090Kb+bM80bKpJmgqv+K/NPlHAmzF51wXSmwVYyqttwaGt2+x9I Tnqk27Mqnv78Cgdqx271PsX/WgeIw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeefhedguddukecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgfgse htqhertderreejnecuhfhrohhmpefnihhnuhhspgeujhpnrhhnshhtrghmuceolhhinhhu shdrihhnthgvrhhnvghtsehfrghsthhmrghilhdrshgvqeenucggtffrrghtthgvrhhnpe ekleevieevleejffetieeltdelkeevteduheefheduieffffdttdegjeeihedtjeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlihhnuhhsrd hinhhtvghrnhgvthesfhgrshhtmhgrihhlrdhsvg X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id BA425AC0072; Sat, 19 Jun 2021 13:59:58 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: <1e959322-f5f8-9bc3-ae08-a30165f9f409@nycap.rr.com> Received-SPF: pass client-ip=64.147.123.25; envelope-from=linus.internet@fastmail.se; helo=wout2-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17614 Archived-At: On Sat, 19 Jun 2021, at 14:16, jerry wrote: > On 6/19/21 7:20 AM, Christopher Lam wrote: > > Agree set! is not a desirable form. It is not consistently optimisab= le.=20 > > I cannot find the reference in the manual. > >=20 > > Also consider the first form: you're building a list in 3 passes -- = call=20 > > iota to generate a list, call filter to navigate the list again, the= n=20 > > fold to accumulate your answer. Therefore it's O(3N). > >=20 > > The preferred form is definitely from the little schemer. > >=20 > Haskell has something called stream fusion which can optimize the extr= a > passes out in many cases. I wonder if Guile or any of the other scheme= > compilers can do that?=20 Hi Jerry! For this to work guile would need to be either pure or lazy. Lazy, becau= se a value would only be pulled through the chain when needed, which wou= ld change the evaluation order in a way that would be compatible with si= de effects. Pure because without side effects fusing two loops can be do= ne without fear. Haskell is of course both. You can get lightweight laziness using srfi-1= 58 - which isn't really loop fusion, but chaining 1000 generator clauses= is still O(n).=20 What guile does have is an eager construct that does something similar t= o loop fusion: transducers. Look at srfi-171. One can compose transducer= s without building want intermediate collections: (list-transduce (compo= se (tfilter even?) (tmap (lambda (x) (quotient x 2)))) + a-list) will ke= ep all even numbers and divide them by 2, and sum them. No intermediate = collections build. They have higher overhead, but are usually faster alr= eady at 2 steps. Best regards Linus Bj=C3=B6rnstam