; factorial-count! : ('init or 'count or natnum) -> (void or natnum) (define factorial-count! (local [; factorial-counter : natnum ; Purpose: Contains the count of the number of times that ; factorial has been computed since the last ; (re)initialization. (define factorial-counter 0) ; factorial : natnum -> natnum ; Purpose: Returns the factorial of the given number. (define (factorial n) (cond [(zero? n) 1] [(positive? n) (* n (factorial (sub1 n)))]))] (lambda (message) (cond [(and (symbol? message) (symbol=? message 'init)) (set! factorial-counter 0)] [(and (symbol? message) (symbol=? message 'count)) factorial-counter] [(number? message) ; factorial could be defined equally well in a local here ; Stylistically, placing all major definitions in one giant ; local (as above) is more common. (begin (set! factorial-counter (add1 factorial-counter)) (factorial message))]))))