nul*_*ter 9 lisp reduce scheme common-lisp fold
我从SICP学到了很多方案,但现在对普通的lisp更感兴趣.我知道普通的lisp fold是reduce,有左或右折叠的特殊参数,但是相当于unfold什么?谷歌搜索没有多大帮助.事实上,我得到的印象是没有展开???
hua*_*uan 13
Common Lisp有(loop ... collect ...).相比
(loop for x from 1 to 10 collect (* x x))
与其等价使用unfold:
(unfold (lambda (x) (> x 10)) (lambda (x) (* x x)) (lambda (x) (+ x 1)) 1)
一般来说,(unfold p f g seed)基本上是
(loop for x = seed then (g x) until (p x) collect (f x))
编辑:修复拼写错误