Fibonacci Numbers

LA home
Computing
FP
 λ-calc.
  Intro
  Syntax
  Examples
   Ints
   Bools
   Lists(1)
   arithmetic
   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. So, nums is the infinite list of Fibonacci numbers. Note that first and F are quite ordinary functions and could be applied to many other lists.




www:

↑ © L. Allison, www.allisons.org/ll/   (or as otherwise indicated).
Created with "vi (Linux)",  charset=iso-8859-1,   fetched Wednesday, 19-Sep-2018 09:45:05 EDT.

Free: Linux, Ubuntu operating-sys, OpenOffice office-suite, The GIMP ~photoshop, Firefox web-browser, FlashBlock flash on/off.