练习3-67
原文
Exercise 3.67. Modify the pairs procedure so that (pairs integers integers) will produce the stream of all pairs of integers (i,j) (without the condition i < j). Hint: You will need to mix in an additional stream.
代码
(define (all-pairs s t) (cons-stream (list (stream-car s) (stream-car t)) (interleave (interleave (stream-map (lambda (x) (list (stream-car s) x)) (stream-cdr t)) (all-pairs (stream-cdr s) (stream-cdr t))) (stream-map (lambda (x) (list x (stream-car t))) (stream-cdr s)))))
感谢您的访问,希望对您有所帮助。 欢迎大家关注或收藏、评论或点赞。
为使本文得到斧正和提问,转载请注明出处:
http://blog.youkuaiyun.com/nomasp
版权声明:本文为 NoMasp柯于旺 原创文章,未经许可严禁转载!欢迎访问我的博客:http://blog.youkuaiyun.com/nomasp
本文介绍如何修改pairs过程,使其能生成所有整数对(i, j),而不限制i必须小于j。通过混合使用额外的流,提供了具体的代码实现,并讨论了interleave、stream-map等函数的应用。
312

被折叠的 条评论
为什么被折叠?



