]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex4_25.rkt
Better explanation of the unless procesure if it is not defined
[sicp.git] / src / sicp / ex4_25.rkt
1 #lang racket
2
3 #|
4
5 The call (factorial 5) will never call 'unless' and will be recursively call 'factorial' for ever. 'n' goes
6 negative and the factorial won't notice it, as it will never get to evaluate the function body of `unless'.
7
8 It will work in a normal order language because none of the arguments of 'unless' are evaluated until
9 they are used inside.
10
11 #lang lazy
12 (define (unless predicate if-exp else-exp)
13   (if (not predicate)
14       if-exp
15       else-exp))
16
17 (define (factorial n)
18   (unless (= n 1)
19           (* n (factorial (- n 1)))
20           1))
21
22 |#