(define (id x) x)
(define (compose func-list)
(define (compose2 acc func-list)
(if (null? func-list)
acc
(let ((first (car func-list))
(rest (cdr func-list)))
(compose2 (lambda (x) (first (acc x))) rest))))
(compose2 id func-list))
((compose (list (lambda (x) (+ x 1))
(lambda (x) (* x 3))
(lambda (x) (- x 1)))) 5)
(define (compose3 func-list)
(if (null? func-list)
id
(let ((first (car func-list))
(rest (cdr func-list)))
(lambda (x)
((compose3 rest) (first x))))))
((compose3 (list (lambda (x) (+ x 1))
(lambda (x) (* x 3))
(lambda (x) (- x 1)))) 5)
(define (r f i xs)
(if (null? xs)
i
(r f (f i (car xs)) (cdr xs))))
(define (compose4 func-list)
(r (lambda (a b)
(lambda (x) (b (a x))))
id
func-list))
((compose4 (list (lambda (x) (+ x 1))
(lambda (x) (* x 3))
(lambda (x) (- x 1)))) 5) |