~tim/scheme-vm

ref: c5110102ce2df2d78a0c87f293edf20f5a3984e7 scheme-vm/examples/fib.scm -rw-r--r-- 348 bytes
c5110102Tim Morgan Add more char functions 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(import (scheme base))

(define (fib n)
  (if (< n 2)
      n
      (+
        (fib (- n 1))
        (fib (- n 2)))))

(define (fib2 n)
  (letrec ((f (lambda (n1 n2 c)
                (if (= c n)
                  n2
                  (f n2 (+ n1 n2) (+ c 1))))))
    (f 0 1 1)))

(write-string (fib 8))
(newline)
(write-string (fib2 8))
(newline)