BYOB 3 Streams Snap!-ified

BYOB Streams Snap!-ified

Wait, didn't we have unevaluated input types back in BYOB? I'm pretty sure we did. Otherwise cons-stream is just cons, and the user has to work below the stream abstraction to understand promises and all that.

Yes. BTW did you make that project?

Yup, although really just copying code from SICP.

I have no Idea what you mean.

Okay. Let's say you write


With me so far? This function works on regular finite lists.

Now we write a new IN FRONT OF block whose second input is of type Any (Unevaluated). (Really it should be List (Unevaluated) to look just like the original, but we don't have that option.)

To simplify this discussion, I'm using unmemoized streams. So the new IN FRONT OF basically just calls the old one:


(The LIST block is needed because the IN FRONT OF primitive gives an error message if its second input is a reporter (as it would be, since TAIL is unevaluated). We''ll undo it later.) So we get this:

which is the new first item, 3, plus a promise to compute the rest of the list later.

The thing is, the user doesn't have to know anything about unevaluated inputs. Saying
untitled script pic (3) means the same thing, as far as the user is concerned, as saying
untitled script pic (4).

Now we rewrite ALL BUT FIRST OF to undo the ringification of the tail of the stream:


This is just an ordinary procedure, nothing magic about it. (Note that the ITEM block is unringified, though.)

Now, from the user's point of view, there's no difference between lists and streams:


We're approaching the moment of truth. We make a tiny change to MAP, using our new versions of
IN FRONT OF and ALL BUT FIRST OF:


And it works, although we need to do some UI work to make that clear:



To beautify this a bit, we can write


Note that we're using the stream version of ALL BUT FIRST OF, because the input is a stream, but the list version of IN FRONT OF, because we want to report a plain list.

I'd like one more little helper:


Okay, we've done a lot of work, with very little to show for it. But now we can make a slight change to the code:


Wait, what? This is a recursion without a base case; if we call it, we'll get an infinite loop.

But we don't:


We can keep butfirsting this stream forever. It's the stream of all integers starting with 3.

What we can't do is SHOW STREAM it; that would be an infinite loop. Here's how we fix it:


And, MAP just works on infinite streams:

I really should remove the "to" input from the NUMBERS FROM block, but it's fun not bothering.

So. Moral of the story. If you, the implementor, do the work to make IN FRONT OF and ALL BUT FIRST OF behave for the user exactly like the regular ones, everything else will just work. If you tell users they have to put rings in IN FRONT OF, then that breaks the abstraction.

I get all that, but

You're the one who did it! If I did it, and I had unevaluated list inputs, then yeah, I would use the uel inputs.

Really? My BYOB version didn't use an unevaluated input in cons-stream?

It didn't! (I have the file, how might I send it to you?)

I'm bh@cs.berkeley.edu, but the trouble is, my shiny new Mac, apart from its other problems, won't run BYOB 3. :~(

Edit: I wonder if that means I wrote it before we added that feature.

Does archive.glitch.pizza work? (the last entry on the dropdown at the bottom of the screen is Chirp, and the four before that are various versions of BYOB)

Whoa, cool!

And you're right. even though we had unevaluated inputs, I didn't use them. Weird. Okay, all my fault.

Wait, do you already have the file?

Yeah, I have a ton of old BYOB3 stuff.

... And I really didn't need to be reminded how slooooooow it was to load a project! :~/

Ah. (Nothing there has help screens. They all beep.)

Edit: I also found out that drag-n-dropping multiple images into BYOB goes through them on-stage and you can't do anything until it's done. (except move the mouse.) Interestingly, whatever you do while it loads the images, it does after the images are done loading, which means BYOB had an event queue. ("queue" is spelled weirdly. "cue", which is pronounced exactly the same, is spelled more reasonably.)

Edit 2:

Edit 3: I just remade MAP in BYOB 2.99, and I just realized that I made it exactly like this: