Created
May 20, 2021 06:20
-
-
Save yanfeng42/c4f32604051cbe3cdfd79d5e9c5909f2 to your computer and use it in GitHub Desktop.
sicp 1.32定义通用高阶 累积 函数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
和社区答案最接近的一次
高阶函数, 威力惊人
如此来看, 从 OOP 入门编程, 反倒是 遮蔽和影响了 自己业务抽象的 理解.