[racket-dev] [plt] Push #25728: master branch updated

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Wed Nov 21 15:34:31 EST 2012

On Wed, Nov 21, 2012 at 2:22 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
> On 2012-11-21 12:50:49 -0600, Robby Findler wrote:
>> On Wed, Nov 21, 2012 at 11:52 AM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
>> > Should queues also be streams or just sequences?
>>
>> I didn't think about this: if you think they should also be streams,
>> that's okay with me. I'm not really sure of the benefits.
>
> I actually asked this because I'm not sure myself. We have two APIs:
> sequences and streams, but it's not entirely clear to me when to prefer
> one over the other.

I've been thinking about this as well. I think that sequences are just
an interface. If you give me a bunch of functions that fit the
interface, then you have a sequence. It's completely extensional. You
dont care how they are implemented. It's the same as iterators in java
and other languages. Streams are a specific kind of sequence where you
have extra requirements on the internal workings (ie
laziness/memoization).

The problem is that in Racket, streams are defined by a it's own,
separate interface (via prop:stream), which (1) is not sufficient
because it doesnt capture the other properties that traditionally
define streams, and (2) is redundant since it largely overlaps with
the sequence interface. So it truly seems like we have two things
(streams and sequences) that are basically the same thing, and one of
the things (streams) is not really what it claims to be. (I'm guessing
in the past, a "stream" in racket was what a sequence is today and
that's where the mixup is coming from?)

Even worse, racket "streams" (the actual implementation, not the
interface) are implemented on top of srfi 41 streams but doesnt use
the srfi correctly so we really do not have streams at all (see pr
13257).

I'm trying to think of the right way to fix things but I think we at
least need to throw out the current streams interface.





>
> Streams support `first`, `rest`, and `empty?`. Sequences don't directly
> support either `first` or `rest`, but with the `sequence-ref` and
> `sequence-tail` functions you can emulate them.
>
> One advantage of streams is that there's now an easy way to implement
> them (via the `gen:stream` generic interface).
>
> Is there a guiding principle behind these APIs?
>
> Cheers,
> Asumu
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev

Posted on the dev mailing list.