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

Racket

Name: Anonymous 2012-09-25 13:28

there must be a better way to do this right


(define (factorial n)
    (define (iter n result)
        (if (= n 0)
            result
            (iter (- n 1) (* result n))))
    (iter n 1))

Name: Anonymous 2012-09-25 19:09

>>26
Are you saying some C compilers don't use the stack, or that its just not necessary? Where the fuck does it keep the thread environment? I suppose C itself isn't really reliant on the stack, which I suppose would explain why you can't access the stack from C.

>>17
I was using the SCIP definition, regarding how frames work with it. http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.1

Scheme uses arcane magic to tail-optimize the function, making it essentially iterative

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