home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / R11SUPP.EXE / FACT.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1990-07-30  |  1.1 KB  |  34 lines

  1. ;;; --------------------------------------------------------------------------;
  2. ;;; FACT.LSP
  3. ;;;   Copyright (C) 1990 by Autodesk, Inc.
  4. ;;;  
  5. ;;;   Permission to use, copy, modify, and distribute this software and its
  6. ;;;   documentation for any purpose and without fee is hereby granted.  
  7. ;;;
  8. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 
  9. ;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 
  10. ;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.
  11. ;;;
  12. ;;; --------------------------------------------------------------------------;
  13. ;;; DESCRIPTION
  14. ;;;
  15. ;;;  This is a programming example of a recursive function which calculates 
  16. ;;;  the factorial of an integer.
  17. ;;;
  18. ;;; --------------------------------------------------------------------------;
  19.  
  20. (defun factor (y) 
  21.   (cond ((= 0 y) 1) 
  22.     (t (* y (factor (1- y))))
  23.   )
  24.  
  25. (defun C:FACT (/ x) 
  26.   (initget 7)                         ;x must not be null, negative or zero
  27.   (setq x (getint "Enter an integer: "))
  28.   (factor (float x))
  29.  
  30. ;;; --------------------------------------------------------------------------;
  31.  
  32.