Hailperin, Chapter 5 Slides, Higher-Order Procudures, functions as parameters Slide of ch5a.rkt ================= (define power (lambda (b e) (if (= e 1) b (* (power b (- e 1)) b)))) (define stack-copies-of (lambda (quantity image) (if (= quantity 1) image (stack (stack-copies-of (- quantity 1) image) image)))) Load ch5a.rkt and demo: > (power 2 1) > (power 2 2) > (power 2 3) > (stack-copies-of 1 rcross-bb) > (stack-copies-of 2 rcross-bb) > (stack-copies-of 3 rcross-bb) Slides, How are the functions similar? Slides, How are the functions different? Slides, together-copies-of, ..., define power Load ch5b.rkt and repeat demo: > (power 2 2) > (stack-copies-of 2 rcross-bb) Slide of ch5c.rkt ================= (define num-digits-in-satisfying (lambda (n test?) (cond ((< n 0) (num-digits-in-satisfying (- n) test?)) ((< n 10) (if (test? n) 1 0)) ((test? (remainder n 10)) (+ (num-digits-in-satisfying (quotient n 10) test?) 1)) (else (num-digits-in-satisfying (quotient n 10) test?))))) Slide, What is the definition of num-odd-digits? Slide, What is the definition of num-6s? Load ch5c.rkt and demo Slides, The Halting Problem After the proof, load ch5d.rkt and show that it compiles. Slides, Procedure factories, Define make-multiplier Load ch5e.rkt (do not show make-repeated-version-of) and demo > (double 7) > (triple 12) Slides, Manufacture a function that calls itself After last slide demo (repeatedly-square 2 2) (repeatedly-square 2 3)