Discuss Scratch

bharvey
Scratcher
1000+ posts

Snap! user discussion

djdolphin wrote:

Maybe.
Well if not how am I going to give you your Alonzo pin?

bharvey
Scratcher
1000+ posts

Snap! user discussion

Hardmath123 wrote:

1. call/cc's lambda doesn't call the continuation;
2. call/cc's lambda does call the continuation;
3. call/cc's lambda stores the continuation somewhere, and somebody else calls it later!

#2 is the case of a THROW; #3 is the case of multithreading/coroutines.

Hardmath123
Scratcher
1000+ posts

Snap! user discussion

bharvey wrote:

djdolphin wrote:

Maybe.
Well if not how am I going to give you your Alonzo pin?
bh++

10/10 those Alonzo pins are pretty awesome.
Hardmath123
Scratcher
1000+ posts

Snap! user discussion

bharvey wrote:

Hardmath123 wrote:

1. call/cc's lambda doesn't call the continuation;
2. call/cc's lambda does call the continuation;
3. call/cc's lambda stores the continuation somewhere, and somebody else calls it later!

#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
Scratcher
1000+ posts

Snap! user discussion

Hardmath123 wrote:

ChocolatePi wrote:

Alright, now I get continuations, but how are they actually used? What do Scheme programmers usually use them for?

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.
Improved try+catch+finally:


Usage:

(btw the forums have syntax highlighting)

Not yet a Knight of the Mu Calculus.
Jonathan50
Scratcher
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
Scratcher
1000+ posts

Snap! user discussion

Jonathan50 wrote:

Can you hide the primitive blocks which don't have codification mappings?
Yes, but not all at once; you right-click each primitive in the palette.
And do you need to manually map custom blocks?
No, I think the idea is that Snap! figures that out.

Jonathan50
Scratcher
1000+ posts

Snap! user discussion

bharvey wrote:

Jonathan50 wrote:

Can you hide the primitive blocks which don't have codification mappings?
Yes, but not all at once; you right-click each primitive in the palette.
And do you need to manually map custom blocks?
No, I think the idea is that Snap! figures that out.
Thanks!
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
Scratcher
1000+ posts

Snap! user discussion

bharvey wrote:

djdolphin wrote:

Maybe.
Well if not how am I going to give you your Alonzo pin?
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? 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.

!
bharvey
Scratcher
1000+ posts

Snap! user discussion

djdolphin wrote:

Alonzo pins sound pretty cool. I'll have to ask my parents if I can go to Scratch Day again.
Yay!!

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.

bharvey
Scratcher
1000+ posts

Snap! user discussion

Jonathan50 wrote:

Can we make new primitive blocks (e.g to turn on a motor in a robot or open a file)?
As far as codification is concerned, any block to which you attach a translation is “primitive.”

Grr, I hate the 60 second rule. Grr.

Jonathan50
Scratcher
1000+ posts

Snap! user discussion

bharvey wrote:

Jonathan50 wrote:

Can we make new primitive blocks (e.g to turn on a motor in a robot or open a file)?
As far as codification is concerned, any block to which you attach a translation is “primitive.”

Grr, I hate the 60 second rule. Grr.
Oh so I can make a custom block which does nothing and map it?

Not yet a Knight of the Mu Calculus.
bharvey
Scratcher
1000+ posts

Snap! user discussion

Jonathan50 wrote:

Oh so I can make a custom block which does nothing and map it?
I don't see why not.

bharvey
Scratcher
1000+ posts

Snap! user discussion

djdolphin wrote:

I'll have to ask my parents
P.S. If they start asking “who is this strange adult…” questions, have them shoot me an email.

DigiTechs
Scratcher
500+ posts

Snap! user discussion

Jonathan50 wrote:

Hardmath123 wrote:

ChocolatePi wrote:

Alright, now I get continuations, but how are they actually used? What do Scheme programmers usually use them for?

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.
Improved try+catch+finally:


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:



And when I meant ‘scope’, I meant something pretty simple like this:


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
Scratcher
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?
bharvey
Scratcher
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?

Hardmath123
Scratcher
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

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
Scratcher
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.

Jens
Scratcher
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!

Powered by DjangoBB