Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

i have a scheme question

Name: Anonymous 2012-07-18 1:56

i have created a function called "repeat" that composes a function with itself n times. i have written it in two different ways. one works and the other doesn't. can you help me understand why the one doesn't work? tia.

the code:
https://gist.github.com/3134464

Name: Anonymous 2012-07-18 3:32

>>8

thank you. that's very helpful.

using that i can rewrite my nonworking repeat function as:

(define (repeat f n)
        (if (> n 1)
              (let ((g (repeat f (- n 1))))
                 (lambda (x)
                               (f (g x))))
          f))

can you explain why it is seemingly necessary to define g outside of the lambda? as in, why can't i remove the let and replace (g x) inside the lambda with (repeat f (- n 1) ?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List