所以compose函数将多个函数结合在一起 假设((撰写sin cos tan asin)0) 所以期望输出为(sin(cos(tan(asin x))))
(define (compose f . g)
(lambda(x)
(if(eq? (cdr g) '())
(f ((car g) x))
(f ((compose (car g) (cdr g)) x))
)
)
)
答案 0 :(得分:1)
(define (compose f . rest)
(if (null? rest)
f
(lambda (x) (f ((apply compose rest) x)))))
(define (foo x) (- x 30))
(define (bar x) (* x 20))
(define (baz x) (+ x 10))
((compose baz) 100) ; 110
((compose bar baz) 100) ; 2200
((compose foo bar baz) 100) ; 2170