home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / elk-2_0.lha / elk-2.0 / examples / scheme / fib < prev    next >
Encoding:
Text File  |  1989-02-17  |  290 b   |  19 lines

  1. ;;; -*-Scheme-*-
  2.  
  3. (define (f n)
  4.   (if (= n 0)
  5.       0
  6.       (let fib ((i n) (a1 1) (a2 0))
  7.     (if (= i 1)
  8.         a1
  9.         (fib (- i 1) (+ a1 a2) a1)))))
  10.  
  11. (print (f 20))
  12.  
  13. (define tau (/ (+ 1 (sqrt 5.0)) 2))
  14.  
  15. (define (fib n)
  16.   (/ (+ (expt tau n) (expt tau (- 0 n))) (sqrt 5.0)))
  17.  
  18. (print (fib 20))
  19.