((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)
Sponsor Sponsor
wtd
Posted: Fri Jan 26, 2007 2:13 am Post subject: RE:Some Scheming
code:
(define (compose func-list)
(letrec ((reduce (lambda (f i xs)
(if (null? xs) i (reduce f (f i (car xs)) (cdr xs)))))
(id (lambda (x) x))
(compose-two (lambda (a b)
(lambda (x) (b (a x))))))
(reduce compose-two id func-list)))
((compose (list (lambda (x) (+ x 1))
(lambda (x) (* x 3))
(lambda (x) (- x 1)))) 5)
wtd
Posted: Fri Jan 26, 2007 12:11 pm Post subject: Re: Some Scheming
code:
(define (compose func-list)
(local ((define (reduce f i xs)
(if (null? xs) i (reduce f (f i (car xs)) (cdr xs))))
(define (id x) x)
(define (compose-two a b)
(lambda (x) (b (a x)))))
(reduce compose-two id func-list)))
((compose (list (lambda (x) (+ x 1))
(lambda (x) (* x 3))
(lambda (x) (- x 1)))) 5)