(define (fib n)
(unfold
(lambda (x) (= (car x) n))
(lambda (x) (cadr x))
(lambda (x) (list (+ (car x) 1) (caddr x) (+ (cadr x) (caddr
x))))
(list 0 0 1) ))
is that good? bad? It passes quite a bit of state information around.
Could it be done better? I'm not used to thinking functionally.
why construct lists?
(define (fib n)
(let loop ((n n) (fibo 1) (fibo0 1))
(if (< n 2) fibo
(loop (- n 1) (+ fibo fibo0) fibo))))
--
a game sig: http://tinyurl.com/d3rxz9
--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
because I was trying to use unfold.