Fibonacci Numbers

LA home
Computing
 Algorithms
 Bioinformatics
 FP,  λ
 Logic,  π
 MML
 Prog.Langs

FP
 Lambda
  Introduction
  Examples
   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.


window on the wide world:

Computer Science Education Week

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite,
ver 3.4+

The GIMP
~ free photoshop
Firefox
web browser
FlashBlock
like it says!

λ ...
:: list cons
nil the [ ] list
null  predicate
hd head (1st)
tl tail (rest)

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University,
was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.)
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Thursday, 18-Sep-2014 05:38:02 EST.