Composition in Lisp
(defun compose-unary-fns (f g)
#’(lambda (x) (funcall f (funcall g x))) )
(setq tripler #’(lambda (x) (* 3 x)))
(setq squarer #’(lambda (x) (* x x)))
(setq triple-squarer
(compose-unary-fns
tripler
squarer) )
(funcall triple-squarer 5)
=> 75
Previous slide
Next slide
Back to first slide
View graphic version