2013-04-10 21:29:02 -07:00
|
|
|
(define (compose f g) (lambda (x) (f (g x))))
|
|
|
|
|
|
|
|
|
|
;; or:
|
|
|
|
|
|
|
|
|
|
(define ((compose f g) x) (f (g x)))
|
2019-09-12 10:33:56 -07:00
|
|
|
|
|
|
|
|
;; or to compose an arbitrary list of 1 argument functions:
|
|
|
|
|
|
|
|
|
|
(define-syntax compose
|
|
|
|
|
(lambda (x)
|
|
|
|
|
(syntax-case x ()
|
|
|
|
|
((_) #'(lambda (y) y))
|
|
|
|
|
((_ f) #'f)
|
|
|
|
|
((_ f g h ...) #'(lambda (y) (f ((compose g h ...) y)))))))
|