Are SRFI/41 and Racket/stream different?

racket, stream

Solution

Yes, the kind of stream that `(in-range 10)` produces is different from `srfi/41` streams. In general, you can't expect `srfi/41` functions to work on all streams in Racket because a Racket "stream" is actually a generic datatype that dispatches to different method implementations (see `gen:stream`). In contrast, `srfi/41` expects only its own datatype.

(`stream-take` should probably be added to `racket/stream` though)

If you want to take 10 items from `racket/stream`, use `(for/list ([x some-stream] [e 10]) x)`.

Problem

`in-range` in Racket returns a stream. There are plenty of functions defined on streams from `racket/stream` library. However i can't use a function `stream-take` from `srfi/41` on them. I wanted to execute ``` (stream-take 5 (in-range 10)) ``` It complained that `stream-take: non-stream argument`. ``` (stream->list (stream-cons 10 (in-range 10))) ``` The above throws the following error: ``` stream-promise: contract violation; given value instantiates a different structure type with the same name expected: stream? given: #<stream> ``` However: ``` (stream->list (stream-cons 10 stream-null)) ;; works (stream->list (stream-cons 10 empty-stream)) ;; works ``` both work fine. Does the above mean that streams from `racket/stream` and `srfi/41` are incompatible? How can i take 10 items from a `racket/stream` stream without reinventing the wheel? Racket 5.3.3

Original source