Mailing List Archive

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

Re: [tlug] "Go Considered Harmful"

On 2020-09-03 21:17 +0900 (Thu), Stephen J. Turnbull wrote:

> I can say it took me a while to realize that if I was going to write
> recursive code in Lisp I should start by writing the stopping
> condition and then the recursive part in the else branch was easier to
> write.  Before I figured that out, it was confusion all the way down.

Yeah. As with anything, there are of course approaches to constructing
these things that one needs to learn. Nothing that an hour with _The Little
Schemer_ won't fix, though.

My main issue of concern with recursion as taught in _The Little Schemer_
is the need to teach what a tail call is and how to convert non-tail-call
recursive functions into tail call form (using accumulators, of course).
It's not difficult to do, and seems reasonably easy to teach, but is it
really essential complexity? Or is dealing with that something that the
language system should do? I'm not totally sure.

But still, aside from that, at least anybody can look at simple recursive
functions even in a language they don't know and understand exactly the
iteration conditions. I happened to be reformatting some BASIC code the
other day (don't ask) and realized that it's not obvious how FOR loops
really work.

Does `FOR I=m TO n` execute the loop with `I=n`? (I.e., does TO mean "up to
and including," or "up to but *not* including"?) Reasonable arguments could
be made either way, and some perhaps hold lesser or greater attraction
depending on your native language. (Do you say, "children under 13," or
"12歳以下の子供"?) It's yet another situation begging for the Bootle

Coming across `FOR I=0 to 0` I thought, "Ah, this makes it clear." After
all, it would be silly to write a loop that's never executed, right? The
loop must include the final value. Of course, on closer examination I
found that this loop actually had body `I = PLAY(0)`, which required
a bit of further thought,

But then, what to make of `FOR I=15 TO 4 STEP -8`? Clearly the loop will
not be run with I=4, but will it be run with I=-1? I guess it depends on
when the value is checked....

¹ "Should array indices start at 0 or 1? My compromise of 0.5 was rejected
  without, I thought, proper consideration." --Stan Kelly-Bootle

Curt J. Sampson      <>      +81 90 7737 2974

To iterate is human, to recurse divine.
    - L Peter Deutsch

Home | Main Index | Thread Index