SICP 問題1.42

2017/09/04

fとgを一引数の関数とする.
gの後のfの合成関数 (composition)は関数x→f(g(x))と定義する合成関数を実装する手続きcomposeを定義せよ.
例えばincが引数に1を足す手続きとすれば

((compose square inc) 6)
; 49

簡単そう。

(define (compose f g)
  (lambda (x) (f (g x))))

; 試す
(define (inc x) (+ x 1))
(define (compose f g)
  (lambda (x) (f (g x))))

((compose square inc) 6)
; 49