灯下 登录
计算机科学 / SICP / 1.3.4 Procedures as Returned Values

Exercise 1.42 · 习题

Exercise 1.42: Let f and g be two
one-argument functions. The
composition f after g is defined
to be the function x

f
(
g
(
x
)
). Define a procedure
compose that implements composition. For example, if inc is a
procedure that adds 1 to its argument,

((compose square inc) 6)

49

练习 1.42:设 f 和 g 是两个单参数函数。f 在 g 之后的复合 (composition) 定义为函数 x ↦ f(g(x))。定义过程 compose 来实现复合。例如,若 inc 是一个给参数加 1 的过程,则

((compose square inc) 6)
49

Racket #lang sicp
((compose square inc) 6)
49