This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#3801 2011-10-09 17:43:01

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Today's vocabulary word

In the script

http://byob.berkeley.edu/cont001.png

we say that the continuation of the block

http://byob.berkeley.edu/cont002.png

is the script

http://byob.berkeley.edu/cont003.png

The continuation means "what is left to do once we compute this result?"  Similarly, the continuation of the block

http://byob.berkeley.edu/cont004.png

is the script

http://byob.berkeley.edu/cont005.png

Note that the continuation of a reporter block is a script with one input, whereas the continuation of a command block is a script with no inputs.

Today's new Snap! feature

CALL / RUN ___ WITH CURRENT CONTINUATION calls or runs its input (which must be a script with one input) with the CALL / RUN...CONTINUATION block's continuation as its input value.  Here's how you'd use it (if only we had lists):

http://byob.berkeley.edu/mult.gif


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#3802 2011-10-09 19:27:15

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Interesting! Will this be a daily post?

Offline

 

#3803 2011-10-10 03:02:26

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

shadow_7283 wrote:

Interesting! Will this be a daily post?

Naw, we're not putting new features in Snap!, at least not until we get the old ones (such as lists) working.

This one is sort of a joke, having to do with the fact that I'm visiting Boston next week.  You know how every time we visit the S.T., they complain that BYOB is too complicated for kids to understand.  Well, in Scheme there are (exactly) two features that really are too complicated for just about anyone to understand: hygienic macros (look it up) and call-with-current-continuation.  So I'm hoping that when I next see Mitchel I can make his head explode.  smile   He won't even have to see a demo; just seeing a block with that name should do it.

If we really want this as a Snap! feature, it needs a more careful design, to work out how much besides the continuation we might need to encapsulate.  For example, suppose some piece of code expects a certain sprite to be hidden, and you make a continuation into it, and later you call the continuation with that sprite shown.  Should we hide the sprite?  And similarly remember the state of all the other sprites?  Call⁄cc works well in Scheme because there's not that much state in a Scheme program; you do everything functionally.

My original idea was just to post "hey, there's a new block in tonight's build" and watch you guys's heads explode too, but the Wikipedia article on call⁄cc is really pretty opaque, so I decided a little bit of explanation was needed.

Call⁄cc can be used for nonlocal exit, as in the MULT example I posted, and also for a scheduler with multiple threads (each represented as a continuation), and also for error handling -- basically any control structure you can imagine can be made with it.  When they invented it for Scheme, it replaced half a dozen or so special-purpose control mechanisms.

The interesting thing is that it's pretty trivial to implement, just a couple of lines in the Javascript code, because the Snap! interpreter already has the continuation of a computation in a variable; that's how it knows where to return when a block finishes running.  So it was just a question of wrapping a lambda around it.

But understanding how to use it is tricky.  Note, for instance, in the MULT picture, that because I used the reporter form of call⁄cc, BREAK is a reporter, but I call it using RUN, not CALL, because the place where I want to call it is a jigsaw-shaped slot.  And that doesn't matter, because when you call or run a continuation, it never returns!  Or rather, it returns someplace else, namely to whoever called call⁄cc to create it.

Jens spent the early part of yesterday saying "maybe later" but once I explained it to him he instantly fell in love with it.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#3804 2011-10-10 13:31:04

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

call/cc

okay, I'm still unsure about a lot of things regarding call/cc, despite being glad that it works. I've been spending the better part of today experimenting with putting the current continuation into an upvar (some of you might have seen a version of this online) and convincing Brian that upvars are just what we need here, so you guys can get it yourselves. But then when Brian finally (gave in) agreed and we came up with a design we both found cool and I got it work I suddenly didn't like it anymore myself, haha! So now, for the moment, I'm back to the most minimalistic block labelling imaginable, call/cc, for both version of the block (command and reporter). As Brian pointed out to me this will be the easiest form for you to look up examples on the internet and in text books, and that really convinces me.


Jens Mönig

Offline

 

#3805 2011-10-10 23:51:31

14God
Scratcher
Registered: 2008-11-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

I'm confused.


http://cs.berkeley.edu/~bh/sig4.png
Logic and reason have led me to atheism... but I'm stuck with the name  tongue

Offline

 

#3806 2011-10-11 09:17:43

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I thought I understood, but when trying to use it in Snap!, I had little success.

Offline

 

#3807 2011-10-11 11:01:44

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Jens wrote:

But then when Brian finally (gave in) agreed and we came up with a design we both found cool and I got it work I suddenly didn't like it anymore myself, haha!

I hate when this happens!  This isn't the first time that each of us has convinced the other about something, and then we really don't know what to do.

For the record, here's what Jens's upvar version looks like (mocked up in BYOB):

http://byob.berkeley.edu/letcc.png

So for example if you do this:

http://byob.berkeley.edu/letex1.png

you are saving the continuation in variable FOO and reporting 5 from the with/do block, so Alonzo says 7 and moves 10 steps.  Then if, later, you do

http://byob.berkeley.edu/letex2.png

you are saying to report 30 from the with/do block, and so Alonzo says 32 and moves 10 steps.

This upvar notation is the BYOBified version of something that's also in the literature under the name "let/cc" -- an alternative version of call⁄cc as a special form, to avoid the confusing fact that there are three different procedures involved with call⁄cc: (1) call⁄cc itself, (2) its input, and (3) the continuation that it creates.  Let/cc is a special form, and instead of a procedure as input it just takes a body (a script, in BYOB), so the only procedure you have to think about is the continuation itself.

@shadow and 14God:  The easiest application of continuations to understand is probably nonlocal exit.  In those other languages you can say things like

Code:

forever {
   ...
   if (something) break;
   ...
}

where "break" means "get me out of the innermost loop."  To do this with let/cc you'd say

http://byob.berkeley.edu/breakex.png

In this simple case, you wouldn't even need the BREAK variable; you could just drag CURRENT CONTINUATION into the RUN block.  But this technique even allows something those other languages can't do, which is nested loops with a separate break command (with a different name) for each loop, so you can exit from as many as you want.

Here's the run/cc equivalent.  It isn't really very different, except that it needs an explicit lambda:

http://byob.berkeley.edu/runccex.png

PS Oops I messed up; "continuation" and "current continuation" in the last picture are supposed to be the same -- it doesn't matter which name you use.

Last edited by bharvey (2011-10-11 11:33:35)


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#3808 2011-10-11 16:12:46

14God
Scratcher
Registered: 2008-11-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

You know, pronouns are kinda like variables, but with very implicit assignment.


http://cs.berkeley.edu/~bh/sig4.png
Logic and reason have led me to atheism... but I'm stuck with the name  tongue

Offline

 

#3809 2011-10-12 09:42:01

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

so... does anybody here actually grok call/cc in Snap? (I sure didn't until Brian personally and patiently tutored me). What's your opinion about our upvar argument, which version do you find helps you better understand this, the plain one or one with upvars?


Jens Mönig

Offline

 

#3810 2011-10-12 10:09:48

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Jens wrote:

But then when Brian finally (gave in) agreed and we came up with a design we both found cool and I got it work I suddenly didn't like it anymore myself, haha!

I hate when this happens!  This isn't the first time that each of us has convinced the other about something, and then we really don't know what to do.

For the record, here's what Jens's upvar version looks like (mocked up in BYOB):

http://byob.berkeley.edu/letcc.png

So for example if you do this:

http://byob.berkeley.edu/letex1.png

you are saving the continuation in variable FOO and reporting 5 from the with/do block, so Alonzo says 7 and moves 10 steps.  Then if, later, you do

http://byob.berkeley.edu/letex2.png

you are saying to report 30 from the with/do block, and so Alonzo says 32 and moves 10 steps.

This upvar notation is the BYOBified version of something that's also in the literature under the name "let/cc" -- an alternative version of call⁄cc as a special form, to avoid the confusing fact that there are three different procedures involved with call⁄cc: (1) call⁄cc itself, (2) its input, and (3) the continuation that it creates.  Let/cc is a special form, and instead of a procedure as input it just takes a body (a script, in BYOB), so the only procedure you have to think about is the continuation itself.

@shadow and 14God:  The easiest application of continuations to understand is probably nonlocal exit.  In those other languages you can say things like

Code:

forever {
   ...
   if (something) break;
   ...
}

where "break" means "get me out of the innermost loop."  To do this with let/cc you'd say

http://byob.berkeley.edu/breakex.png

In this simple case, you wouldn't even need the BREAK variable; you could just drag CURRENT CONTINUATION into the RUN block.  But this technique even allows something those other languages can't do, which is nested loops with a separate break command (with a different name) for each loop, so you can exit from as many as you want.

Here's the run/cc equivalent.  It isn't really very different, except that it needs an explicit lambda:

http://byob.berkeley.edu/runccex.png

PS Oops I messed up; "continuation" and "current continuation" in the last picture are supposed to be the same -- it doesn't matter which name you use.

Ah! Loop-breaking!  smile
I was wondering if the sprite-background interface can handle all the new features in Snap!, or, rather, that Snap! is too advanced to the sprite-background interface. For a simple example, imagine JS Canvas programming with the sprite interface—now you suddenly are restricted to pre-made images, and simple line drawing. Ew!
An interface I might suggest would be the Interface Builder (Mac apps) interface. Basically, you can drag in objects like a loading bar, and link it to a variable (called an IBOutlet). Objects have their own methods and properties. So, I can drag a loading bar on to my app's screen, link it up to a variable called Loading_Bar, then run a block that could look like this:
http://www.imgpaste.com/zWVW.png
(The original Objective-C code would be [Loading_Bar startAnimation];)

Here's an Interface Builder screenshot where I'm hooking up a button with the text Close Window to the method Close Window of the Window.
http://www.imgpaste.com/jKfg.png (too wide to display, sorry!)

Last edited by Hardmath123 (2011-10-12 10:21:17)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3811 2011-10-12 10:21:02

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hi Hardmath123,

you can already do this kind of GUI-Building with Morphic.js:

   http://www.scratch.mit.edu/ext/youtube/?v=QUDNpl0YJqA

which we're creating Snap on top of. But we're probably not going to include "widgets" in Snap, instead we prefer that you create your own ones using our sprite-nesting feature and prototypal inheritance.

Last edited by Jens (2011-10-12 10:21:30)


Jens Mönig

Offline

 

#3812 2011-10-12 10:25:24

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Jens wrote:

Hi Hardmath123,

you can already do this kind of GUI-Building with Morphic.js:

   http://www.scratch.mit.edu/ext/youtube/?v=QUDNpl0YJqA

which we're creating Snap on top of. But we're probably not going to include "widgets" in Snap, instead we prefer that you create your own ones using our sprite-nesting feature and prototypal inheritance.

Yeah, I realize it's beside the point to do stuff for the programmer, as this would be an educational tool (I hope), but I think sprites are a bit too simple for how high BYOB/Snap! programming can be.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3813 2011-10-12 10:47:54

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Maybe you can have a sort of CGSprite make method, which allows you to spontaneously create a totally blank sprite, which can be customized in terms of appearance and position.

Mockup screenshot coming up, 'cause I'm terrible at verbal explanations.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3814 2011-10-12 10:56:10

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

(...) but I think sprites are a bit too simple for how high BYOB/Snap! programming can be.

Ah, thanks for the compliment. See, we're going to have first-class costumes at some point (4.1). Then you'll be able to change every pixel in any costume programmatically and even create new and additional ones using blocks, which really should take care of what you're suggesting.


Jens Mönig

Offline

 

#3815 2011-10-12 10:57:52

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Ah. Well that was what I was aiming at. But here's the mockup, anyway:
http://www.imgpaste.com/fOyr.gif
(New CGSprite) acts like (clone) but extensible.

Last edited by Hardmath123 (2011-10-12 10:58:26)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#3816 2011-10-12 14:09:56

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

@Jens & bharvey
"What's your opinion about our upvar argument, which version do you find helps you better understand this, the plain one or one with upvars?"
Sorry it's exactly like you were talking chinese to me. But no problem I shall try to follow you in any circumstance. By the way Brian is such a nice and patient teacher that all this will come clear for me in due time (not to long because I have just turned my 70 yrs !)

Offline

 

#3817 2011-10-12 17:31:49

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

@Jens&bharvey
I'm just starting to understand that Continuation has similarities with the strange film
"GroundHog day"

Offline

 

#3818 2011-10-12 17:49:04

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Aha, one reason you're all having trouble with call/cc is that there's a bug in our implementation.   sad   Stay tuned...


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#3819 2011-10-12 17:52:54

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

xly wrote:

Continuation has similarities with the strange film "GroundHog day"

Yes, precisely!


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#3820 2011-10-12 18:11:35

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Thank you movie comparison!  big_smile

Offline

 

#3821 2011-10-12 20:46:24

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Okay, try playing with call/cc again; Jens made a temporary fix.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#3822 2011-10-12 20:58:58

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I found a bug. THE BLOCK reports itself when it contains nothing.


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#3823 2011-10-12 21:13:17

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

MathWizz wrote:

I found a bug. THE BLOCK reports itself when it contains nothing.

What would you like it to report?  We actually talked about this case and didn't have a really good answer.  For THE SCRIPT it makes sense to have a zero-length script that does nothing, but not for a reporter block.  We could red-border it; would that be better?


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#3824 2011-10-13 01:03:45

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: BYOB 3 - Discussion Thread

After I posted that I did second guess myself thinking that you more than likely already knew about this but I didn't change it because I was to lazy.  tongue


Anyway... Redborder, maybe... I don't know if this is the direction you want to go in, but you could make another primitive NIL and have it report that.


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#3825 2011-10-13 09:12:27

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

MathWizz wrote:

I found a bug. THE BLOCK reports itself when it contains nothing.

That is ment to happen.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

Board footer