Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以 compose 函数将多个函数组合在一起假设 ((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)) ) ) )
(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