Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Snap! user discussion
- bharvey
-
1000+ posts
Snap! user discussion
Well if not how am I going to give you your Alonzo pin? Maybe.
![](http://cs.berkeley.edu/~bh/sig5.png)
- bharvey
-
1000+ posts
Snap! user discussion
3. call/cc's lambda stores the continuation somewhere, and somebody else calls it later! 1. call/cc's lambda doesn't call the continuation;
2. call/cc's lambda does call the continuation;
#2 is the case of a THROW; #3 is the case of multithreading/coroutines.
![](http://cs.berkeley.edu/~bh/sig5.png)
- Hardmath123
-
1000+ posts
Snap! user discussion
bh++Well if not how am I going to give you your Alonzo pin? Maybe.
10/10 those Alonzo pins are pretty awesome.
- Hardmath123
-
1000+ posts
Snap! user discussion
3. call/cc's lambda stores the continuation somewhere, and somebody else calls it later! 1. call/cc's lambda doesn't call the continuation;
2. call/cc's lambda does call the continuation;
#2 is the case of a THROW; #3 is the case of multithreading/coroutines.
A very cool blog post on continuations: http://matt.might.net/articles/programming-with-continuations–exceptions-backtracking-search-threads-generators-coroutines/
- Jonathan50
-
1000+ posts
Snap! user discussion
Improved try+catch+finally:get continuations, but how are they actually used? What do Scheme programmers usually use them for?Alright, now I
So here's an example. Suppose your language didn't have errors like throw and catch. You know how those work? Like this:try { // Something that can potentially throw an error if (d !== 0) { return 1/d; } else { // Cause an error! throw new Error("Tried to divide by zero!"); } } catch (error) { console.log("An error occurred! This: " + error); } // carry on with life
Now with call/cc, it's possible to INVENT the try/throw/catch construct even though it's not built into Snap!, just like how you can invent the FOR loop.
Here's one way to do it:
http://i.imgur.com/ay0u408.png
See if you can figure out how to make custom error messages like we have in the JS example above.
![](http://i.cubeupload.com/O46Izc.png)
Usage:
![](http://i.cubeupload.com/6AyXnV.png)
(btw the forums have syntax highlighting)
Not yet a Knight of the Mu Calculus.
- Jonathan50
-
1000+ posts
Snap! user discussion
Can you hide the primitive blocks which don't have codification mappings? And do you need to manually map custom blocks?
Not yet a Knight of the Mu Calculus.
- bharvey
-
1000+ posts
Snap! user discussion
Yes, but not all at once; you right-click each primitive in the palette. Can you hide the primitive blocks which don't have codification mappings?
And do you need to manually map custom blocks?No, I think the idea is that Snap! figures that out.
![](http://cs.berkeley.edu/~bh/sig5.png)
- Jonathan50
-
1000+ posts
Snap! user discussion
Thanks!Yes, but not all at once; you right-click each primitive in the palette. Can you hide the primitive blocks which don't have codification mappings?And do you need to manually map custom blocks?No, I think the idea is that Snap! figures that out.
Can we make new primitive blocks (e.g to turn on a motor in a robot or open a file)?
Not yet a Knight of the Mu Calculus.
- djdolphin
-
1000+ posts
Snap! user discussion
Alonzo pins sound pretty cool. I'll have to ask my parents if I can go to Scratch Day again.Well if not how am I going to give you your Alonzo pin? Maybe.
![](http://cdn.scratch.mit.edu/scratchr2/static/__29cebbddad1a2303315dedb62fd76793__/djangobb_forum/img/smilies/tongue.png)
Also, are there plans for a mobile version of Snap? I tried using it on my phone today, but it was a complete mess. For some reason the page was huge, much bigger than the editor, and it kept scrolling to the bottom right corner whenever I tried to do anything.
![](http://cdn.scratch.mit.edu/scratchr2/static/__29cebbddad1a2303315dedb62fd76793__/djangobb_forum/img/smilies/hmm.png)
!
- bharvey
-
1000+ posts
Snap! user discussion
Yay!! Alonzo pins sound pretty cool. I'll have to ask my parents if I can go to Scratch Day again.
Also, are there plans for a mobile version of Snap?Yes. BirdBrain (who make the Finch and Hummingbird robots) have made an iOS one, dunno about Android yet.
I tried using it on my phone today, but it was a complete mess. For some reason the page was huge, much bigger than the editor, and it kept scrolling to the bottom right corner whenever I tried to do anything.It says here you can first tap on top, where the URL bar is hiding, and then pinch to make it small. I agree it's painful. But it's not too bad if you make a project on a computer and then run it on your phone in presentation mode.
![](http://cs.berkeley.edu/~bh/sig5.png)
- bharvey
-
1000+ posts
Snap! user discussion
As far as codification is concerned, any block to which you attach a translation is “primitive.” Can we make new primitive blocks (e.g to turn on a motor in a robot or open a file)?
Grr, I hate the 60 second rule. Grr.
![](http://cs.berkeley.edu/~bh/sig5.png)
- Jonathan50
-
1000+ posts
Snap! user discussion
Oh so I can make a custom block which does nothing and map it?As far as codification is concerned, any block to which you attach a translation is “primitive.” Can we make new primitive blocks (e.g to turn on a motor in a robot or open a file)?
Grr, I hate the 60 second rule. Grr.
Not yet a Knight of the Mu Calculus.
- bharvey
-
1000+ posts
Snap! user discussion
I don't see why not. Oh so I can make a custom block which does nothing and map it?
![](http://cs.berkeley.edu/~bh/sig5.png)
- bharvey
-
1000+ posts
Snap! user discussion
P.S. If they start asking “who is this strange adult…” questions, have them shoot me an email. I'll have to ask my parents
![](http://cs.berkeley.edu/~bh/sig5.png)
- DigiTechs
-
500+ posts
Snap! user discussion
Improved try+catch+finally:get continuations, but how are they actually used? What do Scheme programmers usually use them for?Alright, now I
So here's an example. Suppose your language didn't have errors like throw and catch. You know how those work? Like this:try { // Something that can potentially throw an error if (d !== 0) { return 1/d; } else { // Cause an error! throw new Error("Tried to divide by zero!"); } } catch (error) { console.log("An error occurred! This: " + error); } // carry on with life
Now with call/cc, it's possible to INVENT the try/throw/catch construct even though it's not built into Snap!, just like how you can invent the FOR loop.
Here's one way to do it:
http://i.imgur.com/ay0u408.png
See if you can figure out how to make custom error messages like we have in the JS example above.
Usage:
(btw the forums have syntax highlighting)
Fairly certain that ‘finally’ is meant to run whether it succeded or not - so you can just run the main block, which runs the continuation in case of an error, and then after that has all ran, just run the finally block.
Also, is there any way to define a block for a scope? (that is, a set of command blocks wrapped around a C) It would be quite awesome to be able to define a ‘throw’ block in a try/catch/finally block so you wouldn't have to do 'run (throw) with inputs ')
EDIT: This is what I meant with the try/catch/finally:
![](http://i.cubeupload.com/Qydrfm.png)
![](http://i.cubeupload.com/owOXFu.png)
And when I meant ‘scope’, I meant something pretty simple like this:
![](http://i.cubeupload.com/YqhuSr.png)
Obviously this code will error because ‘b’ is not defined in the scope it is trying to be accessed in
Last edited by DigiTechs (Jan. 23, 2016 13:34:36)
I do, in fact, have my own site; it's here.
I'm also working on a thing called Fetch. Look at it here!
@thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain.
- Hardmath123
-
1000+ posts
Snap! user discussion
Hmm, good question. What would be really cool is a (DYNAMIC (_)) reporter which takes a variable name and looks it up dynamically rather than lexically in just that place (that would solve your RUN problem). But it might lead to ugly hacks, since we're actually just re-inventing a subset of macros and Brian might have bigger plans on that frontier.
Brian?
Brian?
- bharvey
-
1000+ posts
Snap! user discussion
Well, we have hybrid scope (or we're supposed to – at one point there was a bug in it), i.e., if no lexical binding is found for a variable, Snap! will try again dynamically.
Jens doesn't like block scope. We had a big argument about it, and compromised on this: If a name that's already bound in this script appears in a SCRIPT VARIABLES again in the same script, a new variable is created, and earlier uses of the name refer to the earlier variable. (The argument was actually about upvars, but an upvar is treated like a script var with respect to the caller's scope.)
And yes, macros are coming, but not soon. Big lists are imminent, and then OOP, and then we can think about self-reflection.
But the reference to macros confused me. You two must have some shared understanding that I'm not getting about what you want block scope for?
Jens doesn't like block scope. We had a big argument about it, and compromised on this: If a name that's already bound in this script appears in a SCRIPT VARIABLES again in the same script, a new variable is created, and earlier uses of the name refer to the earlier variable. (The argument was actually about upvars, but an upvar is treated like a script var with respect to the caller's scope.)
And yes, macros are coming, but not soon. Big lists are imminent, and then OOP, and then we can think about self-reflection.
But the reference to macros confused me. You two must have some shared understanding that I'm not getting about what you want block scope for?
![](http://cs.berkeley.edu/~bh/sig5.png)
- Hardmath123
-
1000+ posts
Snap! user discussion
Well, he wants to invent some mechanism in the try/catch thing where instead of doing “RUN (break)” to break, you can just do “break”. Now, the easiest way would be if we could have a stack-shaped upvar. Then you just name it “break” and assign it to the function that does run/cc.
But we don't have a stack-shaped upvar, so I suggested being able to do something like
so when you put THROW in the “try” part of try/catch, it'll find “break” defined by the upvar and run that instead of lexically trying to find a globally defined “break” that might not actually exist (even if it did, it would be *wrong*).
This connects to macros because in Scheme, this is like
(In practice, this probably won't work because of hygiene. Ugh.) EDIT: https://docs.racket-lang.org/guide/parameterize.html
P.S. There could also be a VARIABLE input type which creates a dropdown list of variables. Then you could have a generic BREAK block that can break anywhere given a continuation (i.e. does exactly the same thing as RUN but has different title-text!). But that's a completely different discussion that doesn't solve this problem.
But we don't have a stack-shaped upvar, so I suggested being able to do something like
define throw
run (dynamically look up [break v] :: variables) :: control
so when you put THROW in the “try” part of try/catch, it'll find “break” defined by the upvar and run that instead of lexically trying to find a globally defined “break” that might not actually exist (even if it did, it would be *wrong*).
This connects to macros because in Scheme, this is like
(define-syntax throw
(lambda (stx) (syntax (break))))
(In practice, this probably won't work because of hygiene. Ugh.) EDIT: https://docs.racket-lang.org/guide/parameterize.html
P.S. There could also be a VARIABLE input type which creates a dropdown list of variables. Then you could have a generic BREAK block that can break anywhere given a continuation (i.e. does exactly the same thing as RUN but has different title-text!). But that's a completely different discussion that doesn't solve this problem.
Last edited by Hardmath123 (Jan. 23, 2016 17:14:30)
- bharvey
-
1000+ posts
Snap! user discussion
Why not just have a global stack of continuations and have BREAK just run the top one (and pop it off)? You'd also have to pop off the top one when exiting the block normally.
![](http://cs.berkeley.edu/~bh/sig5.png)
- Jens
-
100+ posts
Snap! user discussion
here's my current project with continuation test cases:
http://snap.berkeley.edu/snapsource/snap.html#present:Username=jens&ProjectName=continuations&editMode&noRun
That's the core functionality I want Snap to support.
Anybody come up with more / other simple-to-test-and-debug examples?
Thanks!
http://snap.berkeley.edu/snapsource/snap.html#present:Username=jens&ProjectName=continuations&editMode&noRun
That's the core functionality I want Snap to support.
Anybody come up with more / other simple-to-test-and-debug examples?
Thanks!