home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Binaries / examples / basics / fib.ml next >
Encoding:
Text File  |  1993-09-24  |  443 b   |  20 lines  |  [TEXT/ttxt]

  1. (* The Fibonacci function, once more. *)
  2.  
  3. let rec fib n =
  4.   if n < 2 then 1 else fib(n-1) + fib(n-2)
  5. ;;
  6.  
  7. if sys__interactive then () else
  8. if vect_length sys__command_line <> 2 then begin
  9.   print_string "Usage: fib <number>";
  10.   print_newline()
  11. end else begin
  12.   try
  13.     print_int(fib(int_of_string sys__command_line.(1)));
  14.     print_newline()
  15.   with Failure "int_of_string" ->
  16.     print_string "Bad integer constant";
  17.     print_newline()
  18. end
  19. ;;
  20.