3 ms·
Seriously: Scheme is guaranteed to have tail-call replacement, the author should really take advantage of that. Here's one that does: (define (fib-tco n)
by nanny 11y ago
Seriously: Scheme is guaranteed to have tail-call replacement, the author should really take advantage of that.
Here's one that does:
(define (fib-tco n)
(let loop ((x 0)
(y 1)
(num n))
(if (zero? n)
x
(loop y (+ x y) (- num 1)))))
Try getting the 1000th Fibonacci number which each of these.
Also, what's with the dangling parentheses?