readable/factorial.slisp
David A. Wheeler e13f2ac9e2 factorial.*lisp: Improve Common Lisp short demo files.
- In particular, rename "fact" to "factorial" so the demo
    doesn't interfere with the built-in factorial function.
2014-11-18 17:38:07 -05:00

26 lines
828 B
Text

; This is a demo of sweet-expressions in Common Lisp.
; This version uses QuickLisp, and thus will try to automatically
; download and install the library if it's not available locally. Run as:
; sbcl --script factorial.slisp
; To run the NOT installed readable version, prepend with:
; CL_SOURCE_REGISTRY="$PWD"
#-quicklisp
(let ((quicklisp-init ; Work around clisp failure to load quicklisp.
(merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
(let ((*standard-output* (make-broadcast-stream))) ; Disable noisy output
(ql:quickload "readable"))
(readable:enable-sweet)
defun factorial (x)
if {x < 1}
1
{x * factorial{x - 1}}
format t "Demo factorial of 5 using sweet-expressions:~%"
princ factorial(5)
terpri()