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

#4976 2012-04-25 01:18:59

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

Re: BYOB 3 - Discussion Thread

Yeah. I don't think an empty reporter should be allowed in the first place, it's like saying (lambda) in Scheme. And if that returns an error, why can't Snap? Or maybe it could report NULL (will you have NULL in Snap?).


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

Offline

 

#4977 2012-04-25 01:30:59

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

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

And if that returns an error, why can't Snap?

Yeah, it can and should.  We just haven't gotten to error handling yet.

Page 200!  big_smile


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

Offline

 

#4978 2012-04-25 01:53:27

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

Re: BYOB 3 - Discussion Thread

Ok, but will you have NULL in Snap! anyway? It's a useful procedure error.

Also, can I have references to variables in Snap!? For example, can I write an "increment" function that takes in a variable and returns the variable + 1, while changing the value of the variable by 1 (i.e. i++)? If a variable is an input to a procedure, the procedure automatically makes a duplicate of it, rather than allowing me to change the original value...

I know arrays are automatically treated as references in Snap!, but how about numbers and strings? How can I reference those?

Last edited by Hardmath123 (2012-04-25 01:56:09)


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

Offline

 

#4979 2012-04-25 02:23:56

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

blob8108 wrote:

So "23" + "10" = "2310", but 23 + 10 = 33. Is that an improvement?

Yeah, it's better, I suppose.  What does "23" + 10 do?

Throws an error.

The new ring things look nice!  smile  Empty reporters should report nil/NULL/None, I think. (I'm not sure which "null" is/would be in Snap...)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#4980 2012-04-25 04:24:14

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

blob8108 wrote:

So "23" + "10" = "2310", but 23 + 10 = 33. Is that an improvement?

Yeah, it's better, I suppose.  What does "23" + 10 do?

Also "2310".

I support rings at the top of each palette.
And also a NULL value.

Offline

 

#4981 2012-04-25 06:03:06

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

scimonster wrote:

bharvey wrote:

blob8108 wrote:

So "23" + "10" = "2310", but 23 + 10 = 33. Is that an improvement?

Yeah, it's better, I suppose.  What does "23" + 10 do?

Also "2310".

Not in Python  tongue


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#4982 2012-04-25 06:12:15

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

scimonster wrote:

bharvey wrote:


Yeah, it's better, I suppose.  What does "23" + 10 do?

Also "2310".

Not in Python  tongue

It does in other languages.  tongue

Offline

 

#4983 2012-04-25 10:16:56

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

scimonster wrote:

blob8108 wrote:

scimonster wrote:

Also "2310".

Not in Python  tongue

It does in other languages.   tongue

javascript is evil  smile
but THAT is really a bad thing to do...

Offline

 

#4984 2012-04-25 12:36:56

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

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Ok, but will you have NULL in Snap! anyway? It's a useful procedure error.

I'm not sure I understand this.  Do you mean "it's useful for a custom block to have a conventional value to report to indicate a user error"?  I'd rather have an ERROR block that takes a text string as input and gives that error message.

Also, can I have references to variables in Snap!? For example, can I write an "increment" function that takes in a variable and returns the variable + 1, while changing the value of the variable by 1 (i.e. i++)? If a variable is an input to a procedure, the procedure automatically makes a duplicate of it, rather than allowing me to change the original value...

You can do this in BYOB:

http://i1172.photobucket.com/albums/r578/byobsnap/increment.png

It doesn't seem to quite work in Snap! yet, but Jens will fix it.  smile

I know arrays are automatically treated as references in Snap!, but how about numbers and strings? How can I reference those?

Numbers and strings are not mutable, so there's no point in having a reference to one, in the way I think you're thinking.

Of course, as in any Lisp dialect, really everything is a reference; the only data type is "pointer."  But if the underlying value isn't mutable, there's no way to know that.


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

Offline

 

#4985 2012-04-25 12:40:55

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

Re: BYOB 3 - Discussion Thread

roijac wrote:

javascript is evil  smile

Hey, at least it has a real lambda, unlike a certain other language that will remain nameless because I'm an adult and way too mature to start a flame war.


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

Offline

 

#4986 2012-04-25 13:02:59

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

Ok, but will you have NULL in Snap! anyway? It's a useful procedure error.

I'm not sure I understand this.  Do you mean "it's useful for a custom block to have a conventional value to report to indicate a user error"?  I'd rather have an ERROR block that takes a text string as input and gives that error message.

In some situations, is it not more useful to report nothing than to throw an error? Maybe that's what Hardmath's getting at...  smile

roijac wrote:

javascript is evil  smile

Hey, at least it has a real lambda, unlike a certain other language that will remain nameless because I'm an adult and way too mature to start a flame war.

Flame war aside, I'm now just really intrigued — to which language do you refer?  tongue


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#4987 2012-04-25 13:20:18

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

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

In some situations, is it not more useful to report nothing than to throw an error?

At the risk of sounding Clintonian, I'm not sure whether you mean "report 'nothing'" or "not report anything."  If the former, you don't need a special feature; you can use the word "nothing" (or "NULL" if you prefer), or False, or 0, or whatever floats your boat.  If the latter, all that would happen is that the enclosing block, the one to which you're not reporting anything, will throw a less meaningful error.

I'm not convinced that it's a good idea to blur the distinction between these two possibilities.

But I do think it's useful to be able to have a block that sometimes does and sometimes doesn't report a value.  Then, for example, we could have a single block for RUN and CALL, which basically do the same thing.  The block would report iff its input block reports.  Sadly, the otherwise-really-valuable Scratch block shapes don't allow for that.

Flame war aside, I'm now just really intrigued — to which language do you refer?

Python!  It has a sort-of lambda, but very restricted.


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

Offline

 

#4988 2012-04-25 13:27:04

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

blob8108 wrote:

In some situations, is it not more useful to report nothing than to throw an error?

At the risk of sounding Clintonian, I'm not sure whether you mean "report 'nothing'" or "not report anything."  If the former, you don't need a special feature; you can use the word "nothing" (or "NULL" if you prefer), or False, or 0, or whatever floats your boat.  If the latter, all that would happen is that the enclosing block, the one to which you're not reporting anything, will throw a less meaningful error.

I'm not convinced that it's a good idea to blur the distinction between these two possibilities.

Ah... I meant the first one, "report 'nothing'". I hadn't thought of the second; and I can see how it's confusing. :S

Python!  It has a sort-of lambda, but very restricted.

I love Python; but I absolutely agree with this.  tongue  Its lambda only really lets you have a single line; for multi-line functions you have to declare them and then refer to them by name — you can't have anonymous functions  sad

I much prefer the closures in JS for this reason  smile  Especially being able to refer to variables from the parent context.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#4989 2012-04-25 13:50:59

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

Ok, but will you have NULL in Snap! anyway? It's a useful procedure error.

I'm not sure I understand this.  Do you mean "it's useful for a custom block to have a conventional value to report to indicate a user error"?  I'd rather have an ERROR block that takes a text string as input and gives that error message.

Well, I guess a parallel would be how some example functions in JS tutorials return "-1" for errors in factorial scripts if the input is negative. Except, NULL is easier to stretch to other operations. For example, getting item N of a list of size N-1 could return NULL. Similarly, an empty ring reporter could return NULL (did I say that already?). NULL can also be a reporter block, so I can do something like this:

if <(item (n) of [list v]) = (NULL)>
say [Oops!]
end

Also, can I have references to variables in Snap!? For example, can I write an "increment" function that takes in a variable and returns the variable + 1, while changing the value of the variable by 1 (i.e. i++)? If a variable is an input to a procedure, the procedure automatically makes a duplicate of it, rather than allowing me to change the original value...

You can do this in BYOB:

http://i1172.photobucket.com/albums/r57 … rement.png

It doesn't seem to quite work in Snap! yet, but Jens will fix it.  smile

Ah. I was trying something similar in Snap!, so that was the problem.

I know arrays are automatically treated as references in Snap!, but how about numbers and strings? How can I reference those?

Numbers and strings are not mutable, so there's no point in having a reference to one, in the way I think you're thinking.

Of course, as in any Lisp dialect, really everything is a reference; the only data type is "pointer."  But if the underlying value isn't mutable, there's no way to know that.

I had to read that a couple of times before realizing I couldn't possibly understand it. How can the only data type be a pointer? A pointer's gotta point to something, the only something left is data...

I never really understood pointers. In C, a pointer's something to do with memory locations. So I guess a variable is a value, a pointer is the location at which the value is stored. Have I got that right, or is there scope for further confusion?

Last edited by Hardmath123 (2012-04-25 13:56:31)


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

Offline

 

#4990 2012-04-25 14:31:10

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I never really understood pointers. In C, a pointer's something to do with memory locations. So I guess a variable is a value, a pointer is the location at which the value is stored. Have I got that right, or is there scope for further confusion?

look, in high-level lisp/python like languages, when you define a variable, you set the name of a variable as a pointer to an object in the memory. if you then pass the name, what you pass is a reference to an object, so the function gets an address in the memory where the object is. now, if the object is mutable, you can in-place change it, so if two variables are pointing to this object and you for example call its append method, then it'll change for both variables. if it's not mutable, you can't change it in place, and it doesn't really matter if two variables are pointing to the same object.

for example in python:

Code:

l1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] #l1 is a list (mutable object) you can change in-place using l1.append
l2 = l1
l1.append(11) #In-place change
print l1 #output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
print l2 #output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

t1 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) #t1 is a tuple (imutable lists) you cannot change in-place
t2 = t1
try:
    t1.append(11) #AttributeError: 'tuple' object has no attribute 'append'
except AttributeError:
    print 'Imutable object!'
t1 = t1 + (11) #This is not in-place change-you set t1 to a new object
print t1 #output: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
print t2 #output: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

Offline

 

#4991 2012-04-25 17:25:57

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

You can do this in BYOB:

http://i1172.photobucket.com/albums/r578/byobsnap/increment.png

It doesn't seem to quite work in Snap! yet, but Jens will fix it.  smile

Yup, I sure did! Check it out (and make sure to flush your browser's cache before you do)!

Last edited by Jens (2012-04-25 17:26:38)


Jens Mönig

Offline

 

#4992 2012-04-25 17:41:41

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Post #5000 approaches...
EDIT: Thanks for the pointer explanations! I've always wondered about them.

Last edited by shadow_7283 (2012-04-25 17:50:32)

Offline

 

#4993 2012-04-25 18:30:05

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

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

NULL can also be a reporter block, so I can do something like this:

if <(item (n) of [list v]) = (NULL)>
say [Oops!]
end

Sorry for the delayed response; I had to put some attention into the stuff I actually get paid for.

I think you can't have it both ways.  If you want NULL to mean "I'm reporting that I'm not reporting a value," then you can't equality-test it to something, or use it in any other value-expecting context.  If it doesn't mean that, if NULL is just a value like true or false, I'd rather throw an error than expect users to put a million tests for it after calling your block.  I know they teach you in computer science class to check explicitly for errors, but it makes your code really hard to read, because the parts that do actual work are buried in error-testing parts.  This NULL business got started because C doesn't have a way to throw or catch errors; I think it's an idea whose time has passed.

I had to read that a couple of times before realizing I couldn't possibly understand it. How can the only data type be a pointer? A pointer's gotta point to something, the only something left is data...

I never really understood pointers. In C, a pointer's something to do with memory locations. So I guess a variable is a value, a pointer is the location at which the value is stored. Have I got that right, or is there scope for further confusion?

Thanks to roijac for the Python example.  Did it help?

The term "variable" as understood by a programming languages specialist is a little different from what lay people (including me) mean by it.  So, first, here is the technical definition:  A variable is a location in memory that contains a pointer to a value.  ("Pointer": the memory address of something, the thing it points to.)  Note that in this definition a variable does not have a name!  There is something else called a binding that associates a name with a variable.

For certain purposes it really is useful to make this distinction.  But unless you're writing a compiler (or a PhD thesis about programming languages), it's good enough to say that a variable is the combination of a name and a value.  Or, as non-Lisp programmers put it, a variable has a name, but is a particular place in memory (that might have a value in it).

Lisp programmers think the same thing, except that the value of a variable is always a pointer.  Yes, the pointer points to some other kind of thing, such as an integer or a text string, but the variable itself has as its value the address of that integer or text string.

(Footnote: As an efficiency hack, most real-world compilers, even for Lisp, cheat and handle positive integers smaller than the lowest possible memory address of data by putting the actual integer in the variable, but they make sure there's no way the user can find that out.)

As roijac points out, this becomes important when the underlying value is mutable.  Then you need to know whether the language puts the underlying value in the variable (so that assigning the value to another variable makes a copy) or puts a pointer in the variable (so that assigning the value to another variable makes a copy of the pointer).  But there are other reasons for considering all variables to be of type "pointer."

Namely, there is a big difference between languages that require you to specify the type of a variable (e.g., C, Java) and languages that have untyped variables (e.g, Lisp, Snap!).  In the latter, it's not that there aren't different kinds of data.  Rather, instead of associating a type with a variable, these languages associate the type with a specific value.  So, the value 3 isn't just a single computer word containing the bits 00...011, but a structure including both that computer word and a type tag, i.e., a small integer: 1=integer, 2=list, 3=textstring, etc.  This is why we have to put a pointer in the variable uniformly, even for non-mutable data.  But the advantage is that it's much easier in these languages to deal with heterogeneous data, such as a list containing many different kinds of items.  (The more-than-a-word-ness of typed data is the reason for the footnote above about cheating for small integers, for which the type is implicit.)

The above is probably more than you really wanted to know, sorry.  Here's the bottom line:  If the value of every variable is a pointer, then we don't have to make the pointers explicitly visible to the user.  When you use a variable, we dereference the pointer (i.e., look in the memory location that the pointer addresses) and the user just sees the value pointed to.  In C, where some variables directly contain the underlying value (namely the ones that fit in a computer word) while other variables contain pointers, the pointers have to be explicit in the language and users have to think about them.

Last edited by bharvey (2012-04-25 18:33:05)


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

Offline

 

#4994 2012-04-26 02:42:55

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

@ Jens & bharvey

"Sadly, this change breaks old saved projects; sorry, xly, but Jens thinks this is the last time.Please don't decide you hate it without playing with it for a while!  "

I give you the layman point of view. I understand that "ring" operators replace in a more elegant and concise way the previous "THE SCRIPT" and "THE BLOCK" instructions and also allows to get rid of the touchy "grey-border" operator. Thus I would suggest to leave them in green color inside the operator palette, and not to "overload" RUN and CALL of the Control palette with these rings (incidentally I wonder if it is not an error to have in this palette a CALL with CONTINUATION with a "tooth" ring instead of a "round" ring.)
Concerning the "saving" aspect, I am used since the first start of Snap! to make screen captures of my applications, and it is easy to "rewrite" them, using new instructions. I have adapted one of these using the "ring" operator to store blocks as Items of a list and obviously it is more convenient, elegant and concise compared to previous C-shape  solution.
By the way, is the <property OF sprite > instruction in the pipeline ?

Offline

 

#4995 2012-04-26 03:46:22

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

Re: BYOB 3 - Discussion Thread

Hi Xavier,

the CALL/CC block has a command ring inside because it needs to accepts commands, especially the REPORT block. In the unlikely case that you would like to actually reify a reporter block in there you can exchange the default command ring against a reporter ring yourself! (This is actually easier now than it used to be before we had rings).

the OF block is certainly in the pipeline, but I'm not telling dates  smile


Jens Mönig

Offline

 

#4996 2012-04-26 04:37:26

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

Re: BYOB 3 - Discussion Thread

Thanks for the explanations, roijac and bharvey, really cleared things up!  smile

roijac wrote:

javascript is evil  smile

I can see why you think so. Check these out ([] is empty list, {} is empty object/dictionary, "" is empty string, + is concatenation/addition):

Code:

""+[]=""
[]+""=""
[]+[]=""
[]+{}={}
{}+[]=0 (looks like + is not commutative)
{}+{}=Not a Number (only reasonable answer in this whole series)
{}+""=0
""+{}={} (again, + is not commutative)

XD


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

Offline

 

#4997 2012-04-26 12:16:39

roijac_test
Scratcher
Registered: 2011-08-31
Posts: 49

Re: BYOB 3 - Discussion Thread

yeah, this outputs are really confusing^^  smile

@jens, what about putting the rings in the right-click menu on the palette?

clean up
make a block
rings -> (the three rings in a sub menu)


http://gigabyte.50webs.com/funnyerrormessages/work013.jpg

Offline

 

#4998 2012-04-26 12:23:06

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

xly wrote:

@ Jens & bharvey

"Sadly, this change breaks old saved projects; sorry, xly, but Jens thinks this is the last time.Please don't decide you hate it without playing with it for a while!  "

Maybe any old projects containing (the () block) and (the script {}) are automaticly turned into rings?

Also, I think an empty ring should report the identity function.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#4999 2012-04-26 12:35:32

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

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

Also, I think an empty ring should report the identity function.

Ah, this is a really sensible idea, undoubtedly The Right Thing, but I'm a little scared -- does it apply to the rings automatically provided in Procedure-type input slots?  If so, people who accidentally leave out the function will get a result instead of an error message.  Maybe that's okay -- it's certainly the Scratch Way, but I'm afraid it'll make debugging harder.  Votes?  Thoughts?


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

Offline

 

#5000 2012-04-26 13:15:50

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

well maybe it could be an option? You right click and there is a checkbox menu item "make empty rings report identity" and when it's checked, any empty rings report an identity function, otherwise, you get an error message.

Edit: 5000th POST!!!!!

Last edited by joefarebrother (2012-04-27 14:18:18)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

Board footer