home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / lisp / x / 208 < prev    next >
Encoding:
Text File  |  1992-09-01  |  1.1 KB  |  35 lines

  1. Path: sparky!uunet!olivea!decwrl!pa.dec.com!engage.pko.dec.com!nntpd.lkg.dec.com!sousa.ltn.dec.com!kxovax.enet.dec.com!secrist
  2. From: secrist@kxovax.enet.dec.com (Strong datatypes for weak minds.)
  3. Newsgroups: comp.lang.lisp.x
  4. Subject: n! for xlisp
  5. Keywords: n!
  6. Message-ID: <1674@sousa.ltn.dec.com>
  7. Date: 2 Sep 92 13:57:23 GMT
  8. Sender: newsa@sousa.ltn.dec.com
  9. Organization: Digital Equipment Corporation
  10. Lines: 23
  11.  
  12.  
  13.     kan@dg-rtp.dg.com was nice enough to mail me this, which
  14.     works in XLISP V1.1..2.1 and also traps the negative number 
  15.     case:
  16.  
  17.         (defun factorial (x)
  18.           (cond ((> x 1) (* x (factorial (- x 1))))
  19.             ((> x -1) 1)
  20.             (t nil)))
  21.  
  22.     I think the error in my ways is that I was using my CP/M
  23.     laptop where XLISP 1.1 only has integers in the range of
  24.     -32768 to +37767 and it was too late for me to notice
  25.     why (factorial 9) didn't work.
  26.  
  27.     (Please don't tell me the error in my ways was using CP/M
  28.     in 1992.  I've had my NEC 8400 laptop for ~7 years and can't
  29.     afford anything that small and more powerful on my income...
  30.     otherwise I'd be using Scheme or a Forth-variant like UNTIL.
  31.     Besides, the NEC does words and plays ANSI terminal just fine.)
  32.  
  33.     Regards,
  34.     rcs
  35.