Exercise 4.74: Alyssa P. Hacker proposes to use
a simpler version of stream-flatmap in negate, lisp-value,
and find-assertions. She observes that the procedure that is mapped
over the frame stream in these cases always produces either the empty stream or
a singleton stream, so no interleaving is needed when combining these streams.
Fill in the missing expressions in Alyssa’s program.
(define (simple-stream-flatmap proc s)
(simple-flatten (stream-map proc s)))
(define (simple-flatten stream)
(stream-map ⟨??⟩
(stream-filter ⟨??⟩
stream)))
Does the query system’s behavior change if we change it in this way?
练习 4.74:Alyssa P. Hacker 提议在 negate、lisp-value 和 find-assertions 中使用一个更简单的 stream-flatmap 版本。她注意到,在这些情形下映射到框架流上的过程总是产生空流或单元素流,因此在合并这些流时无需交错。
请填入 Alyssa 程序中缺失的表达式。
(define (simple-stream-flatmap proc s)
(simple-flatten (stream-map proc s)))
(define (simple-flatten stream)
(stream-map ⟨??⟩
(stream-filter ⟨??⟩
stream)))
如果按此方式修改查询系统,系统的行为是否会发生变化?