home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 168.img / ACAD3.ZIP / FACT.LSP < prev    next >
Lisp/Scheme  |  1988-05-25  |  364b  |  15 lines

  1. ;  This is a programming example of a recursive function 
  2. ;  which calculates the factorial of an integer.
  3.  
  4. (defun factor (y)                
  5.    (cond ((= 0 y) 1)
  6.          (t  (* y (factor (1- y))))
  7.    )
  8. )
  9.  
  10. (defun C:FACT (/ x)
  11.    (initget 7)     ;x must not be null, negative or zero
  12.    (setq x (getint "Enter an integer: "))
  13.    (factor (float x))
  14. )
  15.