File: fact.lsp

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (7 lines) | stat: -rw-r--r-- 198 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
(defun fact (n)
       (cond ((zerop n) 1)
	     ((= n 1) 1)
	     (t (* n (fact (- n 1))))))
(defun facti (n &aux (v 1)) ;; Iterative version
       (dotimes (i n) (setq v (* v (1+ i))))
       v)