Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Snap! user discussion
- Jens
- Scratcher
100+ posts
Snap! user discussion
@Kartik: Good question! I've been having a lot of fun with the “aggregate” block, which combines upvars and unevaluated inputs with block variables. I'm still undecided about many, many issues regarding block variables, and not even sure they're a good idea at all. But hey, they're fun! :-)
I guess block vars really turn blocks into objects, and *that*s kinda new, to use stateful objects as part of a programming language. I'm excited about this, just because it's something that you can only ever do in a visual programming language. But again, I'm not sure whether there is some general purpose usefulness in this idea.
I take your question as a suggestion for a “special variable” named “SELF” :-)
I guess block vars really turn blocks into objects, and *that*s kinda new, to use stateful objects as part of a programming language. I'm excited about this, just because it's something that you can only ever do in a visual programming language. But again, I'm not sure whether there is some general purpose usefulness in this idea.
I take your question as a suggestion for a “special variable” named “SELF” :-)
Last edited by Jens (Dec. 16, 2015 10:53:46)
- Jens
- Scratcher
100+ posts
Snap! user discussion
… hey, the SELF idea is actually interesting! If we had that, we could assign it to an upvar and that would open up some fun uses, including sharing block references.
So, now I'm wondering, should SELF be a reserved name, or some special reporter template that pops up when you activate block vars?
(or should I ditch this idea altogether?)
So, now I'm wondering, should SELF be a reserved name, or some special reporter template that pops up when you activate block vars?
(or should I ditch this idea altogether?)
- Jens
- Scratcher
100+ posts
Snap! user discussion
@Brian, are you sure block vars are like STATIC? That's what John mentioned, too, but is it really true? Isn't STATIC a variable that's bound to a particular function, whereas block vars are scoped to a particular function CALL?
- Jens
- Scratcher
100+ posts
Snap! user discussion
… in other words, isn't C's STATIC more like a block CLASS variable, whereas block vars are really block INSTANCE variables?
- Jens
- Scratcher
100+ posts
Snap! user discussion
… the main difference being that STATIC in C isn't thread safe, whereas block vars' only purpose in life is to enable their usage in different threads.
Last edited by Jens (Dec. 16, 2015 10:55:26)
- DrKat123
- Scratcher
1000+ posts
Snap! user discussion
I'm working halfway on the translations
Moving from Scratch? Don't learn C or Java, try Snap!
it haz OOP
DrKat McKatFace
First of all I'm 100% human and humans does not have a cat face
and second, the Boaty McBoatFace/Parsey McParseFace madness has just begun
λ
Sharp, my new Scratch mod
Is my post/siggy worthy for an internet?
- Hardmath123
- Scratcher
1000+ posts
Snap! user discussion
Do you mean that you want the upvar's orange blob to be block-shaped, and maybe have input slots, in the palette?
Yes. The idea, which Jens won't like, is that block-shaped upvars will be “special” in the sense that every time you drag out a block with a block-shaped upvar, its own upvar looks different (maybe a different color or a numerical counter on the block's text or something).
The every example would be:
[make every filter <every ()>]
[say (filter (\ <every (3)>) [a, b, c, d])]
Sorry for the rushed pseudocode; getting late for school and I have a final and a half today.
Last edited by Hardmath123 (Dec. 16, 2015 15:37:59)
- ChocolatePi
- Scratcher
1000+ posts
Snap! user discussion
I was working on a conway's game of life presentation for Hour of Code last week.
I probably shouldn't have used so many lambdas. Half of the class got lost on the third block
I probably shouldn't have used so many lambdas. Half of the class got lost on the third block
- technoboy10
- Scratcher
1000+ posts
Snap! user discussion
Brian, I don't get this. Why is a state var the same thing as a lambda inside a lambda?it's just syntactic sugar for a λ inside a λ Does this mean variables which stay the same during block invocations?
Also why can't my university-level classes be taught in Snap!? I learn more playing with lambdas than I do in a semester of C++
trans rights are human rights
- Hardmath123
- Scratcher
1000+ posts
Snap! user discussion
I don't get this. Why is a state var the same thing as a lambda inside a lambda?
The idea is that you can do something like this:
(define (make-a-counter!) (define N 1) (define (increment-and-report) (set! N (+ N 1)) N))
The “block variables” feature basically implicitly puts the outer “make-a-counter!” lambda and each block variable corresponds to a “(define N 0)”. When you pull a block out of the palette, it executes “make-a-counter!” (which returns a lambda) and the block you just pulled out is defined to be that “inner” lambda that gets reported. So the analogous Snap! for the above is this: https://i.imgur.com/hrOwjdl.png (imgur link to a script pic).
Brian was talking about how we currently can't instantiate block variables to anything other than “0”. It isn't immediately obvious that you can't do “set N to 1” in the block, but that's a problem because the Scheme equivalent is
(define (make-a-counter!) (define (increment-and-report) (set! N 1) (set! N (+ N 1)) N))
which is clearly wrong. There currently is no way to put code between the two “define” lines.
Makes sense?
Last edited by Hardmath123 (Dec. 16, 2015 21:40:44)
- Jonathan50
- Scratcher
1000+ posts
Snap! user discussion
… in other words, isn't C's STATIC more like a block CLASS variable, whereas block vars are really block INSTANCE variables?
#include <stdio.h> void count(void) { static int n = 1; printf("%d\n", n++); } int main() { for(int i = 0; i < 8; i++) count(); return 0; }
1
2
3
4
5
6
7
8
Not yet a Knight of the Mu Calculus.
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
Jens's point, which I agree with now that I think about it, is that your code above just makes one counter, whereas the block variables version makes a new counter every time you drag one out of the palette, each with its own count. I wouldn't have said static makes class variables, though, because in this example there's no way to instantiate new counters. For that you'd have to put the counter code inside a lambda so that new ones can be made on the fly. All the C-family languages have some equivalent of lambda these days, but my impression is that they're mostly ugly.#include <stdio.h> void count(void) { static int n = 1; printf("%d\n", n++); } int main() { for(int i = 0; i < 8; i++) count(); return 0; }
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
!? I learn more playing with lambdas than I do in a semester of C++You should've gone to Cambridge like blob! Also why can't my university-level classes be taught in Snap
Did hm succeed in explaining about the nested lambdas to you?
- technoboy10
- Scratcher
1000+ posts
Snap! user discussion
Yes, but money.!? I learn more playing with lambdas than I do in a semester of C++You should've gone to Cambridge like blob! Also why can't my university-level classes be taught in Snap
Did hm succeed in explaining about the nested lambdas to you?Yes, mostly. It still boggles my mind how lambdas can have state though, although I'm sure I'm just forgetting something in the evaluator.
trans rights are human rights
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
You're pretty lucky if your classmates made it through the I probably shouldn't have used so many lambdas. Half of the class got lost on the third block first lambda!
P.S. Why don't people argue for calling it GNU/MacOS? These days all *nix-like systems are full of GNU applications.
- ChocolatePi
- Scratcher
1000+ posts
Snap! user discussion
I think their whole thing (which is kind of dumb) is that Linuxes are built on “core” GNU utilities, as opposed to just including GNU applications.You're pretty lucky if your classmates made it through the I probably shouldn't have used so many lambdas. Half of the class got lost on the third block first lambda!
P.S. Why don't people argue for calling it GNU/MacOS? These days all *nix-like systems are full of GNU applications.
- Jonathan50
- Scratcher
1000+ posts
Snap! user discussion
You're pretty lucky if your classmates made it through the I probably shouldn't have used so many lambdas. Half of the class got lost on the third block first lambda!
P.S. Why don't people argue for calling it GNU/MacOS? These days all *nix-like systems are full of GNU applications.
No, not GNU applications, it's 4.4BSD-lite and FreeBSD applicationsI think their whole thing (which is kind of dumb) is that Linuxes are built on “core” GNU utilities, as opposed to just including GNU applications.You're pretty lucky if your classmates made it through the I probably shouldn't have used so many lambdas. Half of the class got lost on the third block first lambda!
P.S. Why don't people argue for calling it GNU/MacOS? These days all *nix-like systems are full of GNU applications.
Last edited by Jonathan50 (Dec. 17, 2015 00:35:58)
Not yet a Knight of the Mu Calculus.
- bharvey
- Scratcher
1000+ posts
Snap! user discussion
OK, this is getting kind of off topic (my fault for replying to a sig) but my Mac comes with gcc, gmake, etc. And I'm pretty sure emacs, although I installed Aquamacs. No, not GNU applications, it's 4.4BSD-lite and FreeBSD applications
- Jonathan50
- Scratcher
1000+ posts
Snap! user discussion
oh okOK, this is getting kind of off topic (my fault for replying to a sig) but my Mac comes with gcc, gmake, etc. And I'm pretty sure emacs, although I installed Aquamacs. No, not GNU applications, it's 4.4BSD-lite and FreeBSD applications
(yes it does have GNU emacs)
wait Xcode doesn't have gcc anymore it uses clang/LLVM
[/offtopic]
Last edited by Jonathan50 (Dec. 17, 2015 01:03:24)
Not yet a Knight of the Mu Calculus.
- xly
- Scratcher
100+ posts
Snap! user discussion
@Brian or Jens
Sorry to be very low profile, after this high level discussion, but how FILL instruction can be used ?
Thanks
Sorry to be very low profile, after this high level discussion, but how FILL instruction can be used ?
Thanks