Re: Computing fibonacci numbers (rank newbie)




Jeff:

I forgot to edit FIB-RECUR 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 fib-recur (x &optional (y 0))
(cond ((zerop (1+ x)))
(t (print (fibber y))
(fib-recur (1- x) (1+ y))
(values))))
FIB-RECUR


(defun fibber (x)
(if (or (= x 0) (= x 1))
1
(+ (fibber (- x 1))
(fibber (- x 2)))))
FIBBER


(fib-recur 8)
1
1
2
3
5
8
13
21
34



agthompson

.



Relevant Pages

  • Re: Naval Railgun: Barrel Design or Power Supply?
    ... > Guided munitions are rockets or gravity bombs; even the acceleration ... > of conventional artillery is too much for guidance systems. ... > You need sensors with no moving parts and we aren't there yet. ...
    (sci.physics)
  • Re: Damn you, FEDEX! or Nikon D40 lost in Springfield, MO blackhole.
    ... the 2 mp Mavica he had been using with a Nikon D40. ... After shopping around, he got me to order one for him. ... The shipper had it insured, but from what I have read it could take weeks to sort this crap out. ... You may get your insurance from FedEx and a couple weeks later they find it and deliver it. ...
    (alt.photography)
  • Re: python 3 constant
    ... is require Python to change to accommodate your need. ... Can you see the slight difference? ... Best regards, ...
    (comp.lang.python)
  • Re: The Sci-Fi Rejection Letter That Time Forgot
    ... nations have stockpiled arsenals of these incredible bombs and the time the story is set. ...
    (rec.arts.sf.written)
  • Re: Wachstumssaison Flieder
    ... Handbreit über dem Boden. ... "Fliederkrimi" am Samstag halten heute meine Nerven nicht aus. ... Dorothee ...
    (de.rec.garten)