Re: Computing fibonacci numbers (rank newbie)
 From: viper2 <visionat@xxxxxxxxxxxxxxxxx>
 Date: 23 May 2007 10:00:45 0700
Jeff:
I forgot to edit FIBRECUR to print the Fibonacci numbers in ascending
order, if you prefer things that way. The (VALUES) procedure at the
end of the second COND clause ensures that there is no return value
(i.e., no NIL at the end).
See chapters 7 and 22 of Practical Common Lisp by Peter Seibel for
additional iterative versions for computing Fibonacci numbers using DO
and LOOP.
(defun fibrecur (x &optional (y 0))
(cond ((zerop (1+ x)))
(t (print (fibber y))
(fibrecur (1 x) (1+ y))
(values))))
FIBRECUR
(defun fibber (x)
(if (or (= x 0) (= x 1))
1
(+ (fibber ( x 1))
(fibber ( x 2)))))
FIBBER
(fibrecur 8)
1
1
2
3
5
8
13
21
34
agthompson
.
 References:
 Computing fibonacci numbers (rank newbie)
 From: Jeff Rollin
 Re: Computing fibonacci numbers (rank newbie)
 From: viper2
 Computing fibonacci numbers (rank newbie)
 Prev by Date: Common Lisp on 64bits, looking for advice
 Next by Date: Re: I finally understand why I'm not allowed to use Lisp
 Previous by thread: Re: Computing fibonacci numbers (rank newbie)
 Next by thread: Re: Computing fibonacci numbers (rank newbie)
 Index(es):
Relevant Pages
