next up previous
Next: 4.4 The Array Feature Up: 4. ARITHMETIC IN LISP Previous: 4.2 Arithmetic Functions and

4.3 Programming with Arithmetic

The arithmetic functions may be used recursively, just as other functions available to the interpreter. As an example, we define factorial as it was given in Section I.

$n! = {[}n = 0 \rightarrow 1, T\rightarrow nù(n-l)!{]}$DEFINE (( 
        (FACTORIAL (LAMBDA (N) (COND 
        ((ZEROP N) 1) 
        (1 (TIMES N (FACTORIAL (SUB1 N)))) ))) 
))