home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / IFP05.ZIP / FPDEMO.EXE / FIBSEQ < prev    next >
Encoding:
Text File  |  1987-02-09  |  414 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.