gen:stream doc fix?

21 views
Skip to first unread message

John Clements

unread,
Aug 26, 2019, 9:02:15 PM8/26/19
to Racket Users
The gen:stream documentation has this example:


(define-struct list-stream (v)
#:methods gen:stream
[(define (stream-empty? stream)
(empty? (list-stream-v stream)))
(define (stream-first stream)
(first (list-stream-v stream)))
(define (stream-rest stream)
(rest (list-stream-v stream)))])

I believe this example is broken in a sneaky way; the “stream-rest” operation returns a simple list rather than a list-stream. This happens to “work” wrt things like stream-rest and stream-first because lists are also streams. I claim that this should instead read:


(define-struct list-stream (v)
#:methods gen:stream
[(define (stream-empty? stream)
(empty? (list-stream-v stream)))
(define (stream-first stream)
(first (list-stream-v stream)))
(define (stream-rest stream)
(list-stream (rest (list-stream-v stream))))])

Can someone confirm that this is just a typo?

John



Simon Schlee

unread,
Aug 27, 2019, 8:10:20 AM8/27/19
to Racket Users
I agree with your explanation and your version.
I think nobody expects stream-rest to change the concrete type of stream, unless there is a good reason for it.
My guess is that nobody noticed because it happens to work.
Reply all
Reply to author
Forward
0 new messages