home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / ifp / part01 / fproot / demo / FibSeq < prev    next >
Encoding:
Text File  |  1987-07-05  |  396 b   |  18 lines

  1. (*
  2.  * Fibonacci numbers
  3.  * 
  4.  * n : FibSeq -> sequence of first n Fibonacci numbers
  5.  *
  6.  * Example
  7.  *      6 : FibSeq -> <1 1 2 3 5 8>
  8.  *)
  9.  
  10. DEF FibSeq AS
  11.    IF [id,#2] | <= THEN
  12.       [#<1 1>,id] | takel       (* trivial case *)
  13.    ELSE
  14.       sub1 | FibSeq |           (* generate n-1 Fibonacci numbers        *)
  15.       [id, [1r,2r]|+] | apndr   (* append sum of last two to end of list *)
  16.    END;
  17.  
  18.