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-26 3:38

>>43

many c compilers support tail call optimization. The only thing preventing you from getting just as lispy with c is how some statements are hard to make into expressions. Tail call style is more expressive than loops, and can actually end up compiling to faster code, since the equivalent with loops can be a mess with indicator variables. But nevermind. You'll never understand. Go back to scrubbing your toilet bowlhard to find bug buried within the quadruple nested loop caused by a state variable that was initialized 20 lines down to a value that would have made sense if this condition wasn't triggered during this test case as well.

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