Fibonacci Numbers

LA home
   Y (lazy)
   Y (strict)
   Thue seqs.

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 #ad:

↑ © L. Allison,   (or as otherwise indicated).
Created with "vi (Linux)",  charset=iso-8859-1,   fetched Thursday, 02-Feb-2023 14:12:34 UTC.

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