(define-syntax cons-stream
(lambda (x)
(syntax-case x ()
((_ a b) (syntax (cons a (delay b)))))))
(define-syntax car-stream
(lambda (x)
(syntax-case x ()
((_ s) (syntax (car s))))))
(define-syntax cdr-stream
(lambda (x)
(syntax-case x ()
((_ s) (syntax (force (cdr s)))))))
The above macros defined three operation on a stream. Note that the "cons-stream" is not defined a function. But you
can try it. You will find that definition can result in a infinite loop. Why? The scheme interpertor usually evaluates
a value before passing a argument into a parameter of a function. So, before making a stream the scheme interpertor trap
into trying making that infinite stream.
Today is the last work day this year. I have a holiday for four days. I am going to Shanghai again and take Mike yao's
computer, at once I will discuss with him about MPEG4.
本文定义了Scheme语言中用于操作流的三个宏:cons-stream、car-stream 和 cdr-stream。解释了为什么cons-stream不能被定义为函数的原因,并提到了无限递归的问题。
1119

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



