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

#3501 2011-07-31 23:39:49

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

I have a suggestion:

http://i.imgur.com/qYsPY.png

As the image suggests, allow multiple inputs to be visible to the caller and each "made" variable renamed much like the SCRIPT VARIABLES block

With this I can make a script list block (I think), so that would be useful.


http://www.danasoft.com/citysign.jpg

Offline

 

#3502 2011-07-31 23:58:56

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

Re: BYOB 3 - Discussion Thread

Sidharth wrote:

In my opinion, Smalltalk is not the perfect language for a beginner because it is not like most "mainstream" programming languages (Again, that's my opinion).

Well, I have to admit, I've tried teaching myself Smalltalk three times with only limited success, but I don't think it's because of the syntax.  I think it's because all those other languages you mentioned aren't really object-oriented, and Smalltalk is:  Everything is an object.  Integers are objects.  (And, yes, I know, in Java you can wrap a class around an integer, but you can't do arithmetic on those wrappers; you have to pull out the actual integer first.  Smalltalk integers are objects that know how to do arithmetic.)  Programs are objects.  Rectangles are objects.  The debugger is an object -- a class, acually, I guess, of which you get a new instance every time a primitive blows up.  If you've been programming in languages that are mostly traditional with an object overlay, it's hard to wrap your mind around the real thing.

But, about beginners, the reason it's called "Smalltalk" is that it was designed for kids, and the Parc people taught it to kids (middle school, mostly) quite a lot.  And "it's not like other languages" isn't, imho, a reason to reject a language -- after all, BYOB isn't much like Java or JS either!  (Although it is like Scheme, but that's not exactly mainstream either.)

But I'm not trying to push you into Smalltalk, just pointing out that there are really good reasons for its design, and you should understand that it was the source from which everyone else got the idea of OOP.


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

Offline

 

#3503 2011-08-01 00:07:31

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

Re: BYOB 3 - Discussion Thread

Sidharth wrote:

As the image suggests, allow multiple inputs to be visible to the caller and each "made" variable renamed much like the SCRIPT VARIABLES block

Hmm, maybe I'm missing something, but your picture looks to me just like the bottom of our long form input dialog box.

Do you mean that if a block's prototype includes a multiple input named FOO, and the user calls the block with three inputs, you want variables FOO1, FOO2, and FOO3?

If so, it doesn't make sense to me, unless the person writing the block knows that exactly three inputs will be given, in which case there's no need for a multiple input!  Otherwise, how will the block's script know that this time it has to look for a variable FOO27 because the user gave 27 inputs?


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

Offline

 

#3504 2011-08-01 00:20:38

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Sidharth wrote:

As the image suggests, allow multiple inputs to be visible to the caller and each "made" variable renamed much like the SCRIPT VARIABLES block

Hmm, maybe I'm missing something, but your picture looks to me just like the bottom of our long form input dialog box.

Do you mean that if a block's prototype includes a multiple input named FOO, and the user calls the block with three inputs, you want variables FOO1, FOO2, and FOO3?

If so, it doesn't make sense to me, unless the person writing the block knows that exactly three inputs will be given, in which case there's no need for a multiple input!  Otherwise, how will the block's script know that this time it has to look for a variable FOO27 because the user gave 27 inputs?

I did edit the picture to make it look like both of the radiobuttons were pressed...
Just combine the effects of multiple inputs with visible variables, so you can make a block

Code:

FOO (a) >

If you press the >, then you get

Code:

FOO (a) (b) < >

That's what I wanted

I guess coding the block will be hard, but maybe the block creator can use a list to manipulate the values of the blocks, maybe just to initialize them:

Block would look like:

Code:

SCRIPT LIST (a)  >

And the code:
http://i.imgur.com/gIS5d.png

(I am sorry if you cannot read the text, it says "Multiple Visible Inputs".


http://www.danasoft.com/citysign.jpg

Offline

 

#3505 2011-08-01 00:29:15

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Sidharth wrote:

In my opinion, Smalltalk is not the perfect language for a beginner because it is not like most "mainstream" programming languages (Again, that's my opinion).

Well, I have to admit, I've tried teaching myself Smalltalk three times with only limited success, but I don't think it's because of the syntax.  I think it's because all those other languages you mentioned aren't really object-oriented, and Smalltalk is:  Everything is an object.  Integers are objects.  (And, yes, I know, in Java you can wrap a class around an integer, but you can't do arithmetic on those wrappers; you have to pull out the actual integer first.  Smalltalk integers are objects that know how to do arithmetic.)  Programs are objects.  Rectangles are objects.  The debugger is an object -- a class, acually, I guess, of which you get a new instance every time a primitive blows up.  If you've been programming in languages that are mostly traditional with an object overlay, it's hard to wrap your mind around the real thing.

But, about beginners, the reason it's called "Smalltalk" is that it was designed for kids, and the Parc people taught it to kids (middle school, mostly) quite a lot.  And "it's not like other languages" isn't, imho, a reason to reject a language -- after all, BYOB isn't much like Java or JS either!  (Although it is like Scheme, but that's not exactly mainstream either.)

But I'm not trying to push you into Smalltalk, just pointing out that there are really good reasons for its design, and you should understand that it was the source from which everyone else got the idea of OOP.

The funny thing about the Smalltalk browser is that EVERYTHING CAN BE MIDDLECLICKED! Even the scrollbars, the minimize button, etc.

The reason I'm so big on structure is that languages like JS are very similar to English speech patterns (and so is Scratch!)

Code:

if (FOOBAR == "something") {return true;} else {return false;}

The above can be easily translated into English and not lose any structure:
"IF foobar is something, then I will return true, if it is anything ELSE I will return false."

(I think!) This is the Smalltalk equivalent: (I just learned Smalltalk today, don't laugh at my bad coding  smile  )

Code:

foobar="something" ifTrue: [^ true] ifFalse [^ false]

Would you say "foobar is something and IF that is true, then I will return true, and if it is false, I will return false."?

Yeah, yeah you can just return the value foobar == "something" in both examples, but I was using this code to illustrate the difference between the structure of JS (and many other programming languages) and Smalltalk.


http://www.danasoft.com/citysign.jpg

Offline

 

#3506 2011-08-01 00:59:18

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

Re: BYOB 3 - Discussion Thread

Sidharth wrote:

I did edit the picture to make it look like both of the radiobuttons were pressed...

Oh!  I'm so habituated to the idea that "radio buttons" (as opposed to checkboxes) means that you can't push more than one of them that I thought you wanted to push the top button and were erasing the other two!

<digression>I bet you've never even seen one of the old car radios with mechanical channel select buttons interlocked so that when you pushed one, any other one that might have been pushed would pop out.</digression>

Just combine the effects of multiple inputs with visible variables...

Hmm, okay, I'm trying to read your mind and haven't done so well up to now, but I think what you're after is to pass the caller's own variables into your block, but that's not how upvars ("make internal variable visible to caller") work; the scope of the variable is restricted to the block itself.

There already is an official way to do what I think you want, but I'm not sure you'll like it:

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

The block's internal variable VARS contains a list of reporters.  When you call INIT, you give it a bunch of grey-bordered variable ovals; in other words, the list elements are actually THE (FOO) BLOCK and so on.  Then you can pass each of those reporter blocks to SET to initialize the variables to whatever value you want.


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

Offline

 

#3507 2011-08-01 01:18:10

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

Re: BYOB 3 - Discussion Thread

Sidharth wrote:

Would you say "foobar is something and IF that is true, then I will return true, and if it is false, I will return false."?

Ah, but you see, this is part of what I mean about taking OOP seriously rather than just splicing a few OOP-like features onto a traditional language.

Basically, the syntax of traditional programming languages boils down to

VERB OBJECT

or

VERB(OBJECT)

("Object" here in the English-grammar sense, a noun phrase.  In programming language terms, a variable or expression representing some datum.)  But the entire big idea of OOP is to reverse that, so instead of locating the intelligence in the verbs (the procedures) and treating the data as passive, you put the intelligence in the data -- the objects -- and you say

OBJECT MESSAGE

where "message" takes the place of the traditional procedures/operators, but a message is just a piece of text (plus maybe some additional objects), not an algorithm; the algorithm to handle that message is inside the object.

So, first we have

object: foobar
message: = "something"

and since every object knows how to test whether some other object is equal to itself, the result of this is another object whose value is TRUE or FALSE.  Then you send that object an

iftrue:iffalse:

message.  You're right that this is backwards from English (although not backwards from German, which puts the verb at the end of the sentence; maybe that's why Jens is so brilliant at Smalltalk?).  OOP is backwards from procedural programming!  That's why it was a decade between the invention of Smalltalk and the time when anyone in the Real World had a clue what Alan Kay was talking about.  And that was by way of C++, which, like all its descendants, didn't really provide OOP but instead provided generic functions -- functions of the same name that could take inputs of different types -- which is technically more or less equivalent in power to OOP but is very, very different in its underlying metaphor.

Those other languages do let you say

object.message(inputs)

though, and that's only a little different from

object message inputs

in notation, although it's a big shift in emphasis.


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

Offline

 

#3508 2011-08-01 02:14:14

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

But the entire big idea of OOP is to reverse that, so instead of locating the intelligence in the verbs (the procedures) and treating the data as passive, you put the intelligence in the data -- the objects -- and you say

I guess then the main concept of OOP has been lost, because what I learned was:

OOP makes everything an object, and the object has certain properties such as methods and constants. A method can carry out an action, report another object type, or both.

Example: In JS, a string is an object and it has the following properties:

stringObject.length returns the length of the string
stringObject.substr(2, 5) returns a string object which contains the characters 2 through 2+5(=7) of the original string.

Because stringObject.substr(2, 5) returns a string-type object, you can treat it as another string object and you can use stringObject.substr(2, 5).length as opposed to what a non-object-oriented programming language would require you to do: something like strlen(substr(string, 2, 5) ).

I'm not complaining that knowing English barrs me from leaning Smalltalk, but using VERB OBJECT is a lot more easier to do for me.

I am from India, and Indo-european languages are based on using the verb as a modifier to the object, not the object as a modifier to the verb. In most Indian languages "eat your food quickly" would tranlate to "your food quickly eat" or "your food eat quickly". The verb "eat" describes what you should do to "your food". In English, "your food" describes what you "eat".

Back to my old statement, using JS as the block-coding language will really simplify it for me and (maybe) many others, but complexify (is that a word?) it for some people too, reasing being is that JS is a weakly-typed programming language which is very easy to learn.


http://www.danasoft.com/citysign.jpg

Offline

 

#3509 2011-08-01 02:23:56

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hmm, okay, I'm trying to read your mind and haven't done so well up to now, but I think what you're after is to pass the caller's own variables into your block, but that's not how upvars ("make internal variable visible to caller") work; the scope of the variable is restricted to the block itself.

I'm sorry, but either your mind-reading skills need a little bit of polishing (not likely), or my explaining skills need a LOT of polishing (99% of cases). What I meant is for the block-maker to create a block and allow the user to have as many input variables as he/she wants, but the block can handle all of them (preferably through a loop).

Think about the "script variables" block. That has an input field that lets the user "script" n variables to use. What the block does (I think) is just create them and initialize them, but after the script ends, dump them. Basically, if both the radiobuttons "multiple inputs" and "make variables visible to caller" are checked, then you can have a script that has a loop that creates lists and initializes them, ready to be used.
http://i.imgur.com/gIS5d.png

As you can see, the input field can take multiple inputs, but all the program does is initialize them so the program can access the empty lists and add stuff to them because the variables are visible to the caller.

If you didn't understand this, then say so, and I'll post an even more detailed explanation  smile

Oh, and

bharvey wrote:

<digression>I bet you've never even seen one of the old car radios with mechanical channel select buttons interlocked so that when you pushed one, any other one that might have been pushed would pop out.</digression>

<digression>
Not a car radio, but we have a radio/cd player/casette (did I spell that right?)  player (that was bought before I was born) that has some of the play/pause/stop/record buttons interlocked into groups. I have never actually seen one installed in a car.</digression>

Last edited by Sidharth (2011-08-01 02:36:14)


http://www.danasoft.com/citysign.jpg

Offline

 

#3510 2011-08-01 08:21:13

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

Re: BYOB 3 - Discussion Thread

Sidharth wrote:

I am from India, and Indo-european languages are based on using the verb as a modifier to the object, not the object as a modifier to the verb. In most Indian languages "eat your food quickly" would tranlate to "your food quickly eat" or "your food eat quickly". The verb "eat" describes what you should do to "your food". In English, "your food" describes what you "eat".

Ah, but you're not asking your food to eat! In that you're missing the subject. Instead eat is a message you're sending to, say a dog:

   dog eat: food

There, that's better, even in Indo-European, right?

Problem is, those other languages often have implicit objects - often subjects - which they simply ignore. Take Scratch: Each Scratch Block has the implicit receiver Sprite1 (or whatever the receiving object is named). In those "low-level" programming languages the receiving subject often is "the computer". So, whenever you're communicating with "the computer" instead of a data structure you're leaving the OOP sector, regardless of what the syntax is.

Last edited by Jens (2011-08-01 08:23:39)


Jens Mönig

Offline

 

#3511 2011-08-01 09:52:38

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

Re: BYOB 3 - Discussion Thread

I had a [far-fetched] idea. How about, next to /Scripts\/Costumes\/Sounds\, you add /Text Code\. Text code reports the javascript for all scripts present, to simplify sharing/editing.


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

Offline

 

#3512 2011-08-01 11:03:39

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

Jens wrote:

Ah, but you're not asking your food to eat! In that you're missing the subject. Instead eat is a message you're sending to, say a dog:

Eh... sorry, bad example. I was taking "your food:eat quickly" as an imperative command in which pronouns are understood.

So, my question to you is since in C++ there is a function "System()" in the header file "iostream". Does this veer away from OOP? Is that what makes Smalltalk a "pure" language, not having any imperative commands?


http://www.danasoft.com/citysign.jpg

Offline

 

#3513 2011-08-01 12:33:45

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

Re: BYOB 3 - Discussion Thread

Sidharth wrote:

As you can see, the input field can take multiple inputs, but all the program does is initialize them so the program can access the empty lists and add stuff to them because the variables are visible to the caller.

This sort of thing makes mind-reading harder.  I'm pretty sure that the first "the program" means "the block's defining script" whereas the second "the program" means "the caller of the block."  If so, I can only repeat what I said a while back: the scope of an upvar is limited to the block's defining script.  The point of having upvars is that the caller can drag the variable oval into a script that's in the C-slot of a C-shaped block, or into a block that's in a reporter-type input slot.  More simply, you can only use an upvar within the context of the block itself; upvars are unreachable from outside that block.  So even if we let the caller make bunches of upvars, those variables you're initializing couldn't be used after you finish initializing them!

If you want your variables to be usable outside of the initializer block, then you have to create them outside of the block -- either with the "Make a variable" button or with a SCRIPT VARIABLES block in a script in the main scripting area.  And then you can provide those variables, as many as you want, to the initializer block using the technique in my previous message.

P.S.  Of course we could change the semantics of upvars so that they would be added to the caller's scope rather than to the block's own scope, but I think that would be bad for two reasons: (1) it would clutter the collection of permanent variables, and (2) we already have ways to create variables outside the block's scope, whereas there isn't another mechanism to do what upvars do now.  And I think it would be a real kludge to have upvars have two different semantics depending on whether or not you also clicked multiple inputs.


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

Offline

 

#3514 2011-08-01 12:40:11

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

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I had a [far-fetched] idea. How about, next to /Scripts\/Costumes\/Sounds\, you add /Text Code\. Text code reports the javascript for all scripts present, to simplify sharing/editing.

We definitely want to make the JS code for scripts available, maybe not until 4.1 but absolutely something we're working on.  I don't like the fourth tab, though, because if users add JS code that we can't translate back into a script (probably our compiled blocks will use only a subset of JS capabilities) we won't know what to do with it.

It's more likely that we'll have a mechanism to see the JS translation of one script or one block, and maybe edit that.  By narrowing the scope that way, if the user edits the script into something we can't handle, we can just draw a red outline around that one script, or something.

And of course down the road it'd be great if we can provide a translation of the entire program, including the support code from Snap itself,  into JS that can run on its own.


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

Offline

 

#3515 2011-08-01 14:29:36

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

I had a [far-fetched] idea. How about, next to /Scripts\/Costumes\/Sounds\, you add /Text Code\. Text code reports the javascript for all scripts present, to simplify sharing/editing.

We definitely want to make the JS code for scripts available, maybe not until 4.1 but absolutely something we're working on.  I don't like the fourth tab, though, because if users add JS code that we can't translate back into a script (probably our compiled blocks will use only a subset of JS capabilities) we won't know what to do with it.

It's more likely that we'll have a mechanism to see the JS translation of one script or one block, and maybe edit that.  By narrowing the scope that way, if the user edits the script into something we can't handle, we can just draw a red outline around that one script, or something.

And of course down the road it'd be great if we can provide a translation of the entire program, including the support code from Snap itself,  into JS that can run on its own.

You could make a whole library in JS and a move 10 steps block could be:

Code:

scratch.motion.moveSteps(10);

A forever block:

Code:

scratch.control.forever(function () {
    scratch.motion.moveSteps(10);
});

Then the Smalltalk code can parse it and if it sees something other than scratch.* it can get mad.

EDIT: Why was "parse" bleeped? I know what it contains, but really? Watch it get bleeped again...

Last edited by Sidharth (2011-08-01 14:30:51)


http://www.danasoft.com/citysign.jpg

Offline

 

#3516 2011-08-01 14:52:18

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

Re: BYOB 3 - Discussion Thread

Sidharth wrote:

You could make a whole library in JS

Yes, I agree, with luck the same code that runs on our web page will be exportable to other people's programs and the translation will be simple, although, as Jens said, it won't be SCRATCH.whatever but rather SPRITE1.whatever (because, e.g., you have to know which sprite to move 10 steps).

This will work because JS has a real lambda, lexically scoped, and does inheritance by prototyping, fitting right in with our approach.

Indeed, the hardest parts will be the ones in which we have to violate lexical scoping, e.g., when a script is dragged from one sprite to another and loses its variable references.  In that situation we have to go back to the variable name and look it up in the new context.  This is why compiling Snap to JS will work but compiling to anything lower than that, e.g., machine language, would be much harder.


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

Offline

 

#3517 2011-08-01 15:08:36

Sidharth
Scratcher
Registered: 2007-12-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Sidharth wrote:

You could make a whole library in JS

Yes, I agree, with luck the same code that runs on our web page will be exportable to other people's programs and the translation will be simple, although, as Jens said, it won't be SCRATCH.whatever but rather SPRITE1.whatever (because, e.g., you have to know which sprite to move 10 steps).

I was just looking for a way to be able to export/import scripts in a cool way from Scratch into text. Jens made a XML patch thingy, but I couldn't get that to work  sad . I really didn't care whether it ran online, or even was compilable, just wanted something nifty like that  big_smile

I overlooked the idea of using the name of the sprite as the name of the object.

Do you think the idea of making c-inputs as functions themselves is a good idea? I thought it was, but maybe difficult to impliment.

Again, all I wanted was a way to import/export scripts into BYOB so that I can type them somewhere else because in my big projects (text adventures), BYOB goes ultra-slow.

Another idea:
Make a way to export lists?

Code:

LIST foo[1, LIST[1, 2, 3, 4], 4]

As of now, exporting lists that have elements that are lists doesn't work, and with my text adventures I use a HUGE list to describe the area with exits for every room. It took a few hours to type it out with Scratch's minimal list-editing design. If I could type it, it would have taken half the time...

Exporting lists that have objects as elements (sprites) would be hard...

Last edited by Sidharth (2011-08-01 15:09:49)


http://www.danasoft.com/citysign.jpg

Offline

 

#3518 2011-08-01 18:30:36

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

Re: BYOB 3 - Discussion Thread

Sidharth wrote:

Do you think the idea of making c-inputs as functions themselves is a good idea? I thought it was, but maybe difficult to impliment.

Yes, this is already the case.  There is an implicit THE SCRIPT around whatever you put in a C-slot.  (In the technical vocabulary of the reference manual, a C-slot is an Unevaluated input, meaning that it looks like something that's run to provide the input, but actually it's turned into a lambda so that the block can run it repeatedly, run it conditionally, etc.

BYOB goes ultra-slow.

Indeed.  This will be addressed in 4.0, we promise.  And it'll get even better in later releases once we compile every script into JS.

Another idea:
Make a way to export lists?[...]
Exporting lists that have objects as elements (sprites) would be hard...

In order to be able to save projects that have lists of sprites, we have to solve this problem anyway.  But it's true that we can't just represent a sprite as text, the way we can represent list structure with nested brackets.  I think there will be two different exporting mechanisms, "export" and "export as text."  The first will be kind of like the existing mechanism to export a sprite, i.e., the resulting file isn't human-readable but is just a way to get the list into another project.  The second will be human-readable, but will not preserve non-text elements; it'll just say #<sprite1> or something like that.  Import and export should be doable by block as well as in the GUI, although, as I've said before, allowing blocks to read and write the user's disk raises security issues that we have to resolve before we can do that.

All this probably won't be in 4.0 but I hope at least some part of it will be in 4.1.


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

Offline

 

#3519 2011-08-01 18:38:44

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: BYOB 3 - Discussion Thread

Well I must say, you guys (sidharth & bharvey) seem to be having a very in-depth discussion about things I barely understand, but it's interesting to read! I do learn something from it (I think)


http://i.imgur.com/zeIZW.png

Offline

 

#3520 2011-08-01 20:38:14

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

This sort of thing makes mind-reading harder.  I'm pretty sure that the first "the program" means "the block's defining script" whereas the second "the program" means "the caller of the block."  If so, I can only repeat what I said a while back: the scope of an upvar is limited to the block's defining script.  The point of having upvars is that the caller can drag the variable oval into a script that's in the C-slot of a C-shaped block, or into a block that's in a reporter-type input slot.  More simply, you can only use an upvar within the context of the block itself; upvars are unreachable from outside that block.  So even if we let the caller make bunches of upvars, those variables you're initializing couldn't be used after you finish initializing them!

I think I suggested multi-upvars a while ago for two reasons:
- Custom closures for implementing stack tracing, error handling, etc.
- Completely controlled scope of variables, i.e. pretty much what Sidharth was talking about; this is done using a c-shaped block which immediately evaluates its C-input

bharvey wrote:

Import and export should be doable by block as well as in the GUI, although, as I've said before, allowing blocks to read and write the user's disk raises security issues that we have to resolve before we can do that.

You could design the block so that all filestreams opened would be opened on a file selected by the user. This way he/she could cancel the action and would have complete control over what files were accessed. It is a bit limiting, though.

MathWizz wrote:

Nice progress on Snap! I'm running on my iPad but there is a lot of lag. I have a feeling that the final product will have more lag than BYOB 3 if it is not optimized much.  sad

I keep trying it on an iPod touch, but the script execution times out while it's initializing.


nXIII

Offline

 

#3521 2011-08-01 21:03:26

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

Re: BYOB 3 - Discussion Thread

rookwood101 wrote:

Well I must say, you guys (sidharth & bharvey) seem to be having a very in-depth discussion about things I barely understand, but it's interesting to read! I do learn something from it (I think)

Yeah, from time to time we get into these implementation ideas.  But we've also had some fairly basic questions and answers about BYOB capabilities -- taking into account the fact that none of the added capabilities beyond Scratch are entirely "basic."  smile


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

Offline

 

#3522 2011-08-01 21:11:21

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

Re: BYOB 3 - Discussion Thread

nXIII wrote:

- Custom closures for implementing stack tracing, error handling, etc.
- Completely controlled scope of variables, i.e. pretty much what Sidharth was talking about; this is done using a c-shaped block which immediately evaluates its C-input

I can see how a script in the C-slot that says

REPORT [THE SCRIPT ...]

could encapsulate those upvars for export, but I don't see how that's any better than starting the script in the C-slot with a SCRIPT VARIABLES block.  That seems much more straightforward to me.  I'm probably being really dense but I'd have to see a complete example to understand what you guys are getting at.

You could design the block so that all filestreams opened would be opened on a file selected by the user. This way he/she could cancel the action and would have complete control over what files were accessed. It is a bit limiting, though.

That's a great idea.  But I'm not sure it totally solves the problem, because in a lot of cases the Snap user will be a kid, while the computer owner will be the kid's parent or school, and the latter might not trust the kid to understand the full implications of letting an imported project have access to the disk.  I think it really has to be sandboxed, easy everywhere except Windows, but sadly... no, let me not start another flame war.  smile


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

Offline

 

#3523 2011-08-01 21:48:13

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

I don't see how that's any better than starting the script in the C-slot with a SCRIPT VARIABLES block.  That seems much more straightforward to me.  I'm probably being really dense but I'd have to see a complete example to understand what you guys are getting at.

It isn't, except if you need to do more than that. For example, if one wanted to inject a value into a list to reduce it using any number of previous values, he/she could use INJECT (any) AS {value} INTO (list) USING PRECEDING {values...} (commandSlot).
Another example would be (I know I use this example too much) to keep track of the context a program is run in for debugging purposes, etc. To do this you would need to know when variables were declared, using a custom C-shaped variable declaration block VARS {vars...} (commandSlot)

Last edited by nXIII (2011-08-01 21:49:40)


nXIII

Offline

 

#3524 2011-08-02 00:10:38

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

Re: BYOB 3 - Discussion Thread

nXIII wrote:

For example, if one wanted to inject a value into a list to reduce it using any number of previous values, he/she could use INJECT (any) AS {value} INTO (list) USING PRECEDING {values...} (commandSlot).

Sorry, I have no idea what this example means.  Could you give an example of the example?

Another example would be (I know I use this example too much) to keep track of the context a program is run in for debugging purposes, etc. To do this you would need to know when variables were declared, using a custom C-shaped variable declaration block VARS {vars...} (commandSlot)

No, I don't believe this one.  Surely a debugger can't depend on users giving redundant declarations of variables just for the sake of the debugger!  It would have to be done Smalltalk-style: A process is an object and inspectable (including its stack); a procedure is an object and inspectable; a procedure invocation (a stack frame) is an object and inspectable.  The debugger is given the process that faulted as its input, and unearths all the information about variables from there.


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

Offline

 

#3525 2011-08-02 15:08:09

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Sorry, I have no idea what this example means.  Could you give an example of the example?

It's pretty much the JS "reduce" or the Smalltalk "inject", except it gives you previous values for interpolation or something else, e.g. (curly brackets { } show variables)
INJECT <0> AS {currentValue} INTO <list of numbers> USING VALUES {a} {b} < >
    the ( {currentValue} + ( ( {a} + {b} ) / <2>) )
adds the averages of consecutive numbers in the list. (Which is completely useless but demonstrates what it does.)
(Actually, this includes a correction; it should be "USING VALUES" rather than "USING PREVIOUS".)
EDIT: An implementation for this block might be:

inject <start> as <value ^> into <list> using values <v ^ ...> <reporter>
script variables <i>
set <value> to <start>
set <i> to <0>
repeat <length of <v>> [
    change <i> by <1>
    replace item <i> of <v> with <item <1> of <list>>
]
set <i> to <0>
repeat <<length of <list>> - <length of <v>>> [
    change <i> by <1>
    delete <1> of <v>
    add <item <i> of <list>> to <v>
    set <value> to <call <reporter>>
]

No, I don't believe this one.  Surely a debugger can't depend on users giving redundant declarations of variables just for the sake of the debugger!  It would have to be done Smalltalk-style: A process is an object and inspectable (including its stack); a procedure is an object and inspectable; a procedure invocation (a stack frame) is an object and inspectable.  The debugger is given the process that faulted as its input, and unearths all the information about variables from there.

It wouldn't be redundant, e.g.
VARS {a} {b} {c} [
    SET <a> TO 1
    SET <b> TO 2
    SET <c> TO 3
    INSPECT CONTEXT
]

Last edited by nXIII (2011-08-02 15:34:46)


nXIII

Offline

 

Board footer