在HtDP 的练习 30.1.1 中,我开始使用local
,然后将其修改为使用lambda
以回答问题。
(define (add-to-each2 accu a-list)
(cond
[(empty? a-list) empty]
[else (local ((define s (+ accu (first a-list))))
(cons s (add-to-each2 s (rest a-list))))]))
和
(define (add-to-each5 accu a-list)
(cond
[(empty? a-list) empty]
[else (cons ((lambda (x y)
(first (map + (list (first y))
(list x)))) accu a-list)
(add-to-each5 (+ accu (first a-list))(rest a-list)))]))
在这种特殊情况下,对我来说,该local
版本更易于阅读。是否存在lambda
首选版本的情况?谢谢你。