From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: Writing a procedure in different style Date: Sun, 13 Dec 2020 16:01:24 +0100 Message-ID: <66a4948b-6c35-d9df-daa0-865956f52821@posteo.de> References: <3760549b-b32f-fafc-1291-8e3eda7b3753@posteo.de> <2d6f348c-1e43-a5c4-1998-baa04b91bf8c@gmail.com> <1385bd6a-c14e-76f1-6dfe-4cf50d192375@gmail.com> <33683c10-5e29-8e4a-03a4-64852fbcf474@posteo.de> <20201213142412.GB6620@tuxteam.de> 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="20941"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 Cc: guile-user@gnu.org To: tomas@tuxteam.de Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Dec 13 16:01:57 2020 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 1koSsm-0005Mo-W9 for guile-user@m.gmane-mx.org; Sun, 13 Dec 2020 16:01:57 +0100 Original-Received: from localhost ([::1]:40546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koSsl-0000MU-QR for guile-user@m.gmane-mx.org; Sun, 13 Dec 2020 10:01:55 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koSsP-0000ME-US for guile-user@gnu.org; Sun, 13 Dec 2020 10:01:34 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:34623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koSsK-0003px-TL for guile-user@gnu.org; Sun, 13 Dec 2020 10:01:33 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 8AB162400FD for ; Sun, 13 Dec 2020 16:01:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1607871685; bh=m/7jsmfCPJb7NgUYOaM97rziwpeqlpgZTKfXyio/7yg=; h=From:Autocrypt:Cc:Subject:To:Date:From; b=kogIjSvgnCH954ZWULNaUqjzsWapdcbK0vv6wJa6E0qmZxfL/tqhhdB4G7Se1VMnC tyjhrhnJeEDMETm5TP5Vl5JQeJwe3b5tcjGR8enp+8DA5mhoGIHd7Xgzfiviwzx+yo aO3MxrKJa9S7nSO6h7MTNZY7cg7jIVbhzbCU+vMRIaPMXdJLIJbTiaB/hJ5cZ2TMUO 26+FlED2bWIGnq63vZaPOQHqYBglv//slF4zr/h4u8TjzyljTZV9+cw7He7MsadUu3 +xkzpBOwgw+qt15ujX3Em1laj/03BOFOBaTwEuAfWQeFo13KHVzu9f75PtZakBdZl4 zB+2+QPBJkSMg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Cv75K08Rfz9rxM; Sun, 13 Dec 2020 16:01:24 +0100 (CET) Autocrypt: addr=hwroitzsch@posteo.net; prefer-encrypt=mutual; keydata= mQINBF3RPUYBEADWxyXN1cuFxb1XSdrZ6lZ8VlBfD8pYY7oWAAmvjBv4GUAMwMkRYQBPIPFs sRbJC1hGH0qgDN2HhgFQaGEkd0HxLzXiMHvOb9W87i2UyKjZOi8+3weoumcYj5PL9CMj/868 kj2sR9Uu7ovGelbFHZqd4elTZu+DEA/VECsIErewMs9hPA5UuZTLCLoFZEbsXDDy9DvDMpEF jmLCg1lFgTx1Gmj/sWPMja29gvybLYdBSO0lV73aUP2S3rwRgmCpEvh8/sd5TFu1OtewsX4b 1dt9L7ku2sVsx1sh18moi+iUkz6BElno+oBgPGc8NrrDOYHK+Aw2Ko/SZhG0eFa6w/YxuJg3 INMFakvaiiftS6o/qMTTB9KZ2vei2HQ/ua/FoqD+adCYIiMCgGHtdyDOrHQLxZhupvSuAr9V vO30ZpUfx98rjGFRty7QtxCTVDRa2DuYD6vgUNb0kCwrWeQIgwXGEVCEyxYJutOEM5d7leUo MX8zMoT2o3L2E0HdfArj7OmwiYAOaEcWy/LFvOvaJ/mfF5auqqUuLByDwD2RgqMhPwalPV8D prTHfiKm5ITFUD8AYFQvGs6F9kb45ZwnLCGAI9R4eiNSQvQSdwZ6ZvZuAdTzaUa3XcDZogMb a6dhPiFfhSaHLfbtgCgFvlKkN2s0RyqZhJPR4f3UYFEj2pmE2QARAQABtCxIYW5zLVdlcm5l ciBSb2l0enNjaCA8aHdyb2l0enNjaEBwb3N0ZW8ubmV0PokCPQQTAQgAJwUCXdE9RgIbIwUJ CWYBgAULCQgHAg X-Tagtoolbar-Keys: D20201213160124505 In-Reply-To: <20201213142412.GB6620@tuxteam.de> Content-Language: en-US Received-SPF: pass client-ip=185.67.36.66; envelope-from=zelphirkaltstahl@posteo.de; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=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:17079 Archived-At: Hi Tomas! In some way what you write makes sense. Let me state here, that I did read that book and worked through it for a year though, even through the complicated parts like the y-combinator and some chapters I must have read like 4 or 5 times and discovered new aspects on each try. What is typically the case in the book is a different situation though, than what was in Taylan's procedure. Usually it is the list you are working on in that iteration, which you check for being (null? ...), not the thing, that you give as argument to a recursive call or as a return value, which you add in some way to the result. Usually the questions from the quote are asked once the argument is received in the next iteration. That I definitely usually do, but in Taylan's answer there is an (if (null? ...) ...) for the `rest`, inside the case, where the usual (null? ...) check is already done on the subtree, which we recur on. Perhaps I did not recognize the similarity there. Perhaps the rule from TLS is applies more broadly, than I was aware of. And perhaps that is something, that I can take from your reply! Thanks! Anyway, it is at least also new aspect, that I got from Taylan's answer. Regards, Zelphir On 12/13/20 3:24 PM, tomas@tuxteam.de wrote: > On Sun, Dec 13, 2020 at 01:29:31PM +0100, Zelphir Kaltstahl wrote: >> Hello Taylan! >> >> I tried your procedure and indeed it seems to work : ) >> >> I think what I had been missing before were 2 things: >> >> 1. I did not have the (if (null? rest) ...) parts, so I always tried t= o >> directly make a recursive call, perhaps wrapped into a cons, append or= > "When recurring on a list of atoms, /lat/, ask > two questions about it: /(null? lat)/ and *else*. > When recurring on a number, /n/, ask two > questions about it: /(zero? n)/ and *else*. > When recurring on a list of S-expressions, /l/, > ask three question about it: /(null? l)/, /(atom? > ( car l))/, and *else*." > > Daniel P. Friedman and Matthias Felleisen: The Little Schemer [1] > "First Commandment". > > Now before this sounds arrogant or something: this is a botch > I'd be very likely to do myself. That's perhaps why this book, > which at first sight looks so harmless, was for me a joy to read. > > Cheers > > [1] https://pdfs.semanticscholar.org/35d0/d5275a8390c351ce98fbdc2ad37d2= 10ba63b.pdf > > - t --=20 repositories: https://notabug.org/ZelphirKaltstahl