home *** CD-ROM | disk | FTP | other *** search
- ;;; --------------------------------------------------------------------------;
- ;;; FACT.LSP
- ;;; Copyright (C) 1990 by Autodesk, Inc.
- ;;;
- ;;; Permission to use, copy, modify, and distribute this software and its
- ;;; documentation for any purpose and without fee is hereby granted.
- ;;;
- ;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
- ;;; ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
- ;;; MERCHANTABILITY ARE HEREBY DISCLAIMED.
- ;;;
- ;;; --------------------------------------------------------------------------;
- ;;; DESCRIPTION
- ;;;
- ;;; This is a programming example of a recursive function which calculates
- ;;; the factorial of an integer.
- ;;;
- ;;; --------------------------------------------------------------------------;
-
- (defun factor (y)
- (cond ((= 0 y) 1)
- (t (* y (factor (1- y))))
- )
- )
-
- (defun C:FACT (/ x)
- (initget 7) ;x must not be null, negative or zero
- (setq x (getint "Enter an integer: "))
- (factor (float x))
- )
-
- ;;; --------------------------------------------------------------------------;
-
-