Composition in Scheme
(define (compose-unary-fns f g)
(lambda (x) (f (g x))) )
(define tripler (lambda (x) (* 3 x)))
(define squarer (lambda (x) (* x x)))
(define triple-squarer
(compose-unary-fns
tripler
squarer) )
(triple-squarer 5)
=> 75
Previous slide
Next slide
Back to first slide
View graphic version