Fibonacci Numbers

LA home
Computing
FP
 λ-calc.
  Intro
  Syntax
  Examples
   Ints
   Bools
   Lists(1)
   Y (lazy)
   Y (strict)
   Lists(2)
   Trees
   Primes(1)
   Fibonacci(1)
   Unique
   Hamming#s
   Composites
   Fibonacci(2)
   Thue seqs.
   Edit-dist.
   Fibonacci
    Fib'memo-tree

Another circular program - the list nums is defined in terms of itself:

let rec
   first = lambda n. lambda L.
      if n = 0 then nil
      else (hd L)::(first (n-1) tl L),

   nums = 1::(1::(F nums)),

   F = lambda L. (hd L + hd tl L)::(F tl L)

in first 5 nums

{\fB Fibonacci List \fP}

F adds the first two numbers on its input L to form the first element of its output, which in turn becomes part of the input. Note that first and F are quite ordinary functions and could be applied to many other lists.


NB. The applet above needs Java on.
www

free:
Linux operating-sys
OpenOffice office-suite, ver. 2.4+
The GIMP ~photoshop
Firefox web browser
FlashBlock flash on/off

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Wednesday, 07-Jan-2009 21:30:07 EST.