Re: Functional random data streams Marc Nieper-Wißkirchen 05 May 2020 09:25 UTC

Am Di., 5. Mai 2020 um 11:10 Uhr schrieb Shiro Kawai <xxxxxx@gmail.com>:
>
> It is relatively easy to derive lazy streams from generators efficiently (each item consumes one procedure call plus one cons, e.g. srfi-127).
> Deriving generators from lazy streams, on the other hand, involves creation of a thunk for every generator call.   So I prefer having generators first, and lazy streams on top of it.

For most Schemes, this sounds like the best way to implement random
data streams and a converter from generators to SRFI 41 streams would
indeed be a very valuable tool. For Schemes that have been optimized
with respect to lazy semantics (I am thinking of a Scheme built on top
of a Haskell core), however, it may be inefficient to create a
generator and then convert it to a stream.

Thus my request to add a second equivalent set of procedures
addressing streams. For the sample implementation, one could build on
the generator interface, of course, as you propose.

Thanks,

Marc

P.S.: While I cannot say much about the particular efficiency in the
Guile implementation, I agree with Mark Weaver's comment from
https://lists.gnu.org/archive/html/guile-devel/2019-07/msg00000.html
that we should promote functional constructs when there aren't reasons
that stand against it (like efficiency reasons). In this sense, we
should take care that the final collection of stream procedures won't
be smaller than the final collection of generator procedures in
R7RS-large.