Skip to content

Instantly share code, notes, and snippets.

@yanfeng42
Created May 20, 2021 06:20
Show Gist options
  • Save yanfeng42/c4f32604051cbe3cdfd79d5e9c5909f2 to your computer and use it in GitHub Desktop.
Save yanfeng42/c4f32604051cbe3cdfd79d5e9c5909f2 to your computer and use it in GitHub Desktop.
sicp 1.32定义通用高阶 累积 函数
(define (accumulate combiner null-value term a next b)
(if (> a b)
null-value
(combiner (term a)
(accumulate combiner null-value term (next a) next b)
)
)
)
(define (accumulate combiner null-value term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (combiner (term a) result))
)
)
(iter a null-value)
)
(define (product term a next b)
(accumulate * 1 term a next b)
)
(define (sum term a next b)
(accumulate + 0 term a next b)
)
@yanfeng42
Copy link
Author

和社区答案最接近的一次

高阶函数, 威力惊人

如此来看, 从 OOP 入门编程, 反倒是 遮蔽和影响了 自己业务抽象的 理解.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment