码迷,mamicode.com
首页 > 其他好文 > 详细

【SICP练习】136 练习3.67

时间:2015-03-29 10:55:03      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:stream   pairs   condition   hint   procedure   

练习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)))))

【SICP练习】136 练习3.67

标签:stream   pairs   condition   hint   procedure   

原文地址:http://blog.csdn.net/nomasp/article/details/44724675

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!