20-CS-4003-001 Organization of Programming Languages Fall 2017
Recursion

Lambda calculus, Type theory, Formal semantics, Program analysis

    Prev     Next     All lectures        Code

Procedures: Fibonacci Numbers

(define fib
   (lambda (x y n)
      (if (<= n 2)
          x
          (fib (+ x y)
               x
               (- n 1)))))

(define fibonacci
   (lambda (n)
      (fib 1 1 n)))
 -  A tail recursive procedure for computing the nth Fibonacci number. Try it like this:
   (fibonacci 1000)
   ;Value: 4346655768693745643568852767504062580256466051737
   178040248172908953655541794905189040387984007925516929592
   259308032263477520968962323987332247116164299644090653318
   7938298969649928516003704476137795166849228875
which shows that any size integer can be accomodated by Scheme.