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 14:12


(let loop ((n n) (result 1))
  (if (= n 0) result
    (loop (- n 1) (* result n))))

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