[plt-scheme] Android; compiling to Java byte code; Clojure

From: Noel Welsh (noelwelsh at gmail.com)
Date: Thu Nov 22 04:31:33 EST 2007

On Nov 22, 2007 6:01 AM, Benjamin L. Russell <dekudekuplex at yahoo.com> wrote:
> It seems to me that recur and loop together allow a
> more intuitive version of the equivalent of tail
> recursion in this case than the regular tail recursion
> in the equivalent SICP Scheme version.

I don't like calling anything intuitive, as it seems what people mean
by intuitive is really "similar to stuff I already knew".  To me the
recur function is *strange*.  I don't really understand how recursion
points are established.  A recursion point is some kind of dynamically
scoped variable?  If so, that means I can really mess up programs if I
add code between the establishment of a recursion point and the call
to recur.

FWIW, I'd rewrite a SICP's tail-recursive factorial as:

(define (factorial n)
  (define (fact-iter product counter)
    (if (> counter n)
        product
        (fact-iter (* counter product)
                   (+ counter 1))))
   (fact-iter 1 1))

I'd probably also count down, so I can use zero?, and use sub1.  This
makes the code clearer in my opinion.

(define (factorial-2 n)
  (define (fact-iter product counter)
    (if (zero? counter)
        product
        (fact-iter (* counter product)
                   (sub1 counter))))
    (fact-iter 1 n))

N.


Posted on the users mailing list.