晚上!
我需要在 Scheme 中编写一个reduce函数,它就像Python中的内置reduce函数一样工作。在 Scheme 中编写 reduce 函数很容易:
(define (reduce fn lis identity)
(if (null? lis)
identity
(fn (car lis)
(reduce fn (cdr lis) identity))))
但是,此代码与 Python reduce不同,后者仅接受两个参数(函数和要归约的项目列表)。
谁能帮我写一个以这种方式工作的 Scheme 函数?
(>(reduce * '(2 4 5 5)) => 200,是我们教授的例子。)
非常感谢,伙计们。你太有帮助了<3
ETA:非常感谢 Levien 先生和 Jester-Young 先生。您提供了完美的信息量来帮助我自己解决问题。*拥抱