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

"tail recursion" SICP problem

Name: Anonymous 2010-12-29 10:34

Hello.

I read SICP and I find it hard to understand the "tail recursion". He says the book, which is a function of "tail recursion"as he calls himself, and not the other functions. But she does not "tail recursion":

(define (f n)
           (if (= n 0)
             1
             (* n (f (- n 1)))))

This is the "else branch"is called. What's up?

(To my English, forgive me am German makes happily speaks, because I, and to the English.)

Name: Anonymous 2010-12-29 10:45

This english is trolling. No German would make english mistakes in this way.

Name: Anonymous 2010-12-29 10:49

BECAUSE I, AND TO THE ENGLISH!

You don't need (define), use a Y combinator.

Name: Anonymous 2010-12-29 11:26

>>2
Sorry! I do not speak English and I'm using a Google online translator.

Name: Anonymous 2010-12-29 11:36

Tail-recursive version would be

(define (f n)
   (define (f- n acc)
       (if (= n 0)
           acc
           (f- (- n 1) (* acc n))))
   (f- n 1))

Name: Anonymous 2010-12-29 11:55

Y combinator version would be

(lambda (n)
  ((((lambda (f)
       (lambda (n)
         (lambda (a)
           (if (<= n 0) a
               (((f f) (- n 1)) (* a n))))))
     (lambda (f)
       (lambda (n)
         (lambda (a)
           (if (<= n 0) a
               (((f f) (- n 1)) (* a n))))))) n) 1))


I feel the lack of SATORI on /prog/ these days.

Name: Anonymous 2010-12-29 11:56

>>6
It should be noted, that's the Y combinator version of the tail recursive one.

Name: Anonymous 2010-12-29 18:19

>>5
I do not see the difference. Both functions are called f that "else branch." Please help.

Name: HERRU BRAUNU-SAN 2010-12-29 18:31

>>4
Learn English. Until then...

THIS THREAD HAS BEEN REPLACED WITH THE FOLLOWING THREAD:

    Subject: PUDDI
    Message: OP is a Faggot?

Name: Anonymous 2010-12-29 19:24

>>9
Faggot I destroy you.

Name: Faggot I destroy you. 2010-12-29 19:45

Faggot I destroy you.

Name: Anonymous 2010-12-30 2:56

>>8
I do not see the difference. Both functions are called f
Well noted!
The proper tail recursive function would be

(define (tail-recursive-f n)
           (if (= n 0)
             1
             (* n (tail-recursive-f (- n 1)))))

Name: Anonymous 2010-12-30 4:58

proper definition:
(define (f n) (Π 1 n))

Name: Anonymous 2010-12-30 9:43

proper definition:
(define (OP) Faggot)

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