guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing a procedure in different style


From: Zelphir Kaltstahl
Subject: Re: Writing a procedure in different style
Date: Sun, 13 Dec 2020 16:01:24 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

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 to
>> 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/d5275a8390c351ce98fbdc2ad37d210ba63b.pdf
>
>  - t

-- 
repositories: https://notabug.org/ZelphirKaltstahl





reply via email to

[Prev in Thread] Current Thread [Next in Thread]