(This is a template, feel free to delete it.)
The w/continuation blocks dont make any sense
I tried looking in the catch and throw blocks for clues but a “continuation” doesn’t really click in my head
Help lol
(This is a template, feel free to delete it.)
The w/continuation blocks dont make any sense
I tried looking in the catch and throw blocks for clues but a “continuation” doesn’t really click in my head
Help lol
Did you read Chapter X of the Reference Manual?
I second the recommendation to read chapter 10 of the manual. I struggled with the concept of continuations the first time I ran into them (several years ago), and I’ve read several different explanations of what they are. The explanation in the Snap! manual is the best explanation I’ve found out of all the ones I’ve read (congratulations, @bh!).
If you still have questions after reading the chapter, please feel free to ask them and we’ll try to answer anything that’s confusing. But if we try to answer your questions before you’ve read the chapter, our explanations will either be duplicates of what’s already there, or else will just leave you more confused. So reading the chapter first is strongly recommended.
Da manual dont make snese
Basically, a continuation is the script that comes after a certain block.
The continuation of move (100) steps in
pen down
move (50) steps
turn cw (30) degrees
move (100) steps
turn cw (20) degrees
move (40) steps
pen up
would be
turn cw (20) degrees
move (40) steps
pen up
nice explanation, thank you!
It’s maybe helpful to remember that a continuation is a property of a running script, not of a block. It’s what comes after running a script. Usually, what we see in the scripting area are just simple stacks of command blocks, and those don’t have anything happening afterwards. But if a script is embedded into another one, then the next blocks of the other (“outer”) script surrounding the embedded one become the continuation of the ”inner” script. Such “embedded” situations mostly happen when a script is called or run by another one, e.g. inside a ring, a C-shaped slot or if the inner script happens to be the definition of a custom block.
In Snap! continuations are automatically captured whenever a script is evaluated without any memory overhead, that’s why we no longer have to explicitly capture them with a call/cc block such as in Scheme. We only keep call/cc and run/cc around as libraries because there is so much literature about continuations out there that use these - somewhat less elegant - constructs.
Instead, in Snap! we can directly run the continuation within a script to “jump out” of it:
and we can use them to build special control structures such as catch/throw in Snap! itself:
The explanation in the Snap! manual is the best explanation I’ve found out of all the ones I’ve read
Thanks!
a continuation is a property of a running script, not of a block.
In Snap! continuations are automatically captured whenever a script is evaluated without any memory overhead, that’s why we no longer have to explicitly capture them with a call/cc block such as in Scheme. We only keep call/cc and run/cc around as libraries because there is so much literature about continuations out there that use these - somewhat less elegant - constructs.
Umm. We have different ideas about elegance, and Jens’s definition of “continuation” is different from what everyone else means by it.
The root of the problem is that we inherited from Scratch the idea that commands are more important than reporters, and scripts (sequences of commands) are more important than composition of functions.
But computer scientists are more interested in talking about procedures (commands and reporters and predicates) and procedure calls (uses of a procedure in a larger piece of the program). The continuation of a procedure call is all the work that remains to be done after that procedure call returns (stops or reports).
What would be elegant would be if there were only one block shape, an oval with tabs above and below, so that the block could either snap into a script vertically or be put in an input slot of another block.
And then it would be clear that the continuation of a reporter is just as valid as the continuation of a script (or of a step within a script). So, in the expression
![]()
the continuation of the × block is
![]()
(I used an explicit formal parameter product to make it clearer what gets added to 3, but it’d be completely equivalent just to say
![]()
.)
It’s not clear to me why Jens thinks it’s more elegant to restrict the idea of continuations to complete scripts, but I can only fight with him about so many things at once, and since the continuations library still gives us what “continuation” really means, it wasn’t worth fighting about this one.
I guess maybe Jens’s sense of what’s elegant comes from the fact that his version corresponds exactly to a feature of inferior programming languages, namely, the RETURN statement, whereas those inferior languages don’t have anything half as powerful as real first class continuations. (To be clear, what Jens calls “continuations” are first class in Snap!, unlike the situation in those lesser languages. But they’re restricted to only certain procedure calls.)
Thank you, that sums it up
Wait! How do you disagree?
and
mean the same idea with different words!
No, because in your example with the triangular spiral, RUN (THIS CONTINUATION) should be a no-op. You think only complete scripts can have continuations, so THIS CONTINUATION is the end of the script, rather than the context of the call to THIS.
On second thought, though, I misstated the disagreement. It’s not about commands vs. operations; it’s about scripts vs. procedures. I think you got your idea of elegance back in the Scratch days, with no user-defined blocks, so scripts were all you had as a control structure.
hmm… I’m really puzzled by this. I mean, don’t we agree that a continuation is a property of a function call? It’s part of its environment, isn’t it? Sure, every function call has a continuation, but - in Scheme - only exactly one function call has access to it: call/cc. It captures it’s own continuation and passes it on to the function it is calling, that’s why it is a higher order function. In Scheme, only a function call “with /cc” can access the continuation. In Snap!, on the other hand, every function call has access to its continuation. That, sir, is elegant!
I have no idea what you’re even talking about with all the ranting about how things are in Scratch, not in the least. It seems to me that you keep mixing up functions with function calls, static code with evaluation environments.
Well, we don’t have to agree, as long as there’s the continuations library. :~)
turn cw (15) degrees
turn right (15) degrees
turn $clockwise (15) degrees
turn ccw (15) degrees
turn left(15) degrees
turn $counterclockwise (15) degrees
turn cw (15) degrees turn right (15) degrees turn $clockwise (15) degrees turn ccw (15) degrees turn left(15) degrees turn $counterclockwise (15) degrees
Thanks!