XPost: comp.lang.scheme
After a bit of effort, my first working lisp code which is slightly more complex than printing "hello", it returns the nth fibonacci number.
How would you lisp gurus have written the code in the proper lisp way.
(defun fib (n)
(let ( (f0 0) (f1 1) (counter 1) )
(loop
(if (>= counter n) (return-from fib f1) )
(let* ( (tmp f0) )
(setf f0 f1) (setf f1 (+ f1 tmp)) (incf counter)))))
Gauche Scheme
(define (nth-fib n)
(do ((n n (- n 1))
(a 0 b)
(b 1 (+ a b)))
((zero? n) b)))
(map nth-fib (iota 9))
===>
(1 1 2 3 5 8 13 21 34)
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)