CS61A-note
高阶函数抽象本质是更上一级的抽象函数可以作为函数的参数,不能作为控制结构的关键在于抽象出概念函数所在的帧是直接父级
eg1:
12345678910111213141516171819def average(x, y): return (x + y)/2def improve(update, close, guess=1): while not close(guess): guess = update(guess) return guessdef approx_eq(x, y, tolerance=1e-3): return abs(x - y) < tolerancedef sqrt(a): def sqrt_update(x): return average(x, a/x) def sqrt_close(x): return approx_eq(x * x, a) return improve(sqrt_update, sqrt_close)result = sqrt(256)
函数设计是 ...