Discuss Scratch
- Discussion Forums
- » Suggestions
- » A simple way to add First Class Lists
- BookOwl
- Scratcher
1000+ posts
A simple way to add First Class Lists
There have been several suggestions to add first class lists to Scratch, but I think that I have come up with a simple way to add it to Scratch that won't be too confusing. It just needs one new block.
There would have to be some changes to the other list blocks to make this work. All the list blocks would have to be changed to accept variables in the list selection block, and when a variable containing a list reference is put into it, it would change the list the reference points to. If the variable contained a string or number, it would work just like a hacked list block does now.
Although only the new list block would be required to implement this idea, two other blocks would make it far more convenient for certain styles of projects.
These blocks would make Scratch much more powerful.
Please post any comments, questions, or criticisms that you have, I will try to answer every one.
(empty list ::list)Yes, that is the only new block needed! This block returns a reference to an empty list. Perhaps an example will make this clear.
set [my list v] to (empty list ::list)This would make the sprite say 1,2,3 etc. Simple, right?
set [i v] to (0)
repeat (10)
change [I v] by (1)
add (i) to (my list)
end
set [i v] to (0)
repeat (10)
change [i v] by (1)
say (item (I) of (my list)) for (2) secs
There would have to be some changes to the other list blocks to make this work. All the list blocks would have to be changed to accept variables in the list selection block, and when a variable containing a list reference is put into it, it would change the list the reference points to. If the variable contained a string or number, it would work just like a hacked list block does now.
Although only the new list block would be required to implement this idea, two other blocks would make it far more convenient for certain styles of projects.
([thing] in front of (list) :: list)The first block would insert something in the front of the list and then return the list, and the second block would return a list containing everything but the first item of a list.
(all but first of (list) :: list)
These blocks would make Scratch much more powerful.
Please post any comments, questions, or criticisms that you have, I will try to answer every one.
Last edited by BookOwl (May 25, 2016 15:22:29)
who needs signatures
- BookOwl
- Scratcher
1000+ posts
A simple way to add First Class Lists
Yay. Makes sense.
So, is that support?
who needs signatures
- IronBit_Studios
- Scratcher
1000+ posts
A simple way to add First Class Lists
Maybe if I knew what you were suggesting?Yay. Makes sense.
So, is that support?
- BookOwl
- Scratcher
1000+ posts
A simple way to add First Class Lists
I'm suggesting a way to add first class lists, which means you could have lists in lists in lists etc., pass list around in custom blocks, modify arbitrary lists, and lots more.Maybe if I knew what you were suggesting?Yay. Makes sense.
So, is that support?
Why did you say that it makes sense if you didn't know what I was suggesting?
who needs signatures
- IronBit_Studios
- Scratcher
1000+ posts
A simple way to add First Class Lists
Isn't it a workaround? If not, I read it wrong but support anyways.I'm suggesting a way to add first class lists, which means you could have lists in lists in lists etc., pass list around in custom blocks, modify arbitrary lists, and lots more.Maybe if I knew what you were suggesting?Yay. Makes sense.
So, is that support?
Why did you say that it makes sense if you didn't know what I was suggesting?
- BookOwl
- Scratcher
1000+ posts
A simple way to add First Class Lists
I don't think so. You can use hacked blocks to pass the names of lists around and change them, but that is not the same thing. The block I am suggesting creates lists, and returns them, much like in Snap!Isn't it a workaround? If not, I read it wrong but support anyways.I'm suggesting a way to add first class lists, which means you could have lists in lists in lists etc., pass list around in custom blocks, modify arbitrary lists, and lots more.Maybe if I knew what you were suggesting?Yay. Makes sense.
So, is that support?
Why did you say that it makes sense if you didn't know what I was suggesting?
who needs signatures
- Jonathan50
- Scratcher
1000+ posts
A simple way to add First Class Lists
Full support.
It adds a very powerful new feature and makes many changes, yet adds only one block.
It adds a very powerful new feature and makes many changes, yet adds only one block.
Last edited by Jonathan50 (July 1, 2016 23:30:26)
Not yet a Knight of the Mu Calculus.
- Prinseskat
- Scratcher
1000+ posts
A simple way to add First Class Lists
Support, sounds like it could work.
haha funny kumquat meme
- liam48D
- Scratcher
1000+ posts
A simple way to add First Class Lists
Support, it's a simple enough addition. I also doubt it would confuse new scratchers very much. You can put numbers and strings in variables, why not lists? (For that matter, why not sprites.. )
202e-202e-202e-202e-202e UNI-CODE~~~~~
- ChocolatePi
- Scratcher
1000+ posts
A simple way to add First Class Lists
It seems like this, while it could be a cool addition and make first class lists easier, would also be a pain in the @#$%^& to get any real work done using first class lists.
It's a bit like, when working in Lisp, you had to form all your lists out of pairs.
It's a bit like, when working in Lisp, you had to form all your lists out of pairs.
- powershack
- Scratcher
1000+ posts
A simple way to add First Class Lists
I guess support, however since I never really program anything on scratch I wouldn't use this very much XD But it would be cool to use sometimes
- gdpr533f604550b2f20900645890
- Scratcher
1000+ posts
A simple way to add First Class Lists
I saw this topic yesterday, and I'm not sure that I understand this suggestion. So, basically, variables would support a list “data type” as well as numbers, strings and Booleans? Also, what is “first class?” I searched it up, and first class data is basically data which can be passed as an argument, returned, assigned to a variables as well as other acts you can do with primitive types? Being able to create custom blocks which accept lists as arguments would be great.
So, is this correct?
So, is this correct?
(myVar)//This is a variableI probably will support the suggestion and it sounds helpful, but I just don't quite understand it yet.
set [myVar v] to [0 ]//It can be set to a number...
set [myVar v] to [Hello World!] //a String...
set [myVar v] to <key [ v] pressed?> //or a Boolean.
//Now it can be set to a list:
set [myVar v] to (myList :: list)
//These are the shapes of argument lots of different data types:
()::stack//Number
[]//String
<>::Boolean//Boolean
//And now another shape will be added for a list "data type"
- ChocolatePi
- Scratcher
1000+ posts
A simple way to add First Class Lists
First class means being able to pass around things without having to give them a name.
There are some languages with first class functions, which means you can define functions that can be used without having to give them a name.
There are some languages with first class functions, which means you can define functions that can be used without having to give them a name.
- gdpr533f604550b2f20900645890
- Scratcher
1000+ posts
A simple way to add First Class Lists
So, (empty list) is basically a way to pass list values? If I'm understanding “first class” correctly, I would like to have first class lists implemented like this: First class means being able to pass around things without having to give them a name.
There are some languages with first class functions, which means you can define functions that can be used without having to give them a name.
([Hello] [, ] [world!] + -:: list)Is this a first class list?
- ChocolatePi
- Scratcher
1000+ posts
A simple way to add First Class Lists
Wow, correct! That's actually how Snap! implements first-class lists!So, (empty list) is basically a way to pass list values? If I'm understanding “first class” correctly, I would like to have first class lists implemented like this: First class means being able to pass around things without having to give them a name.
There are some languages with first class functions, which means you can define functions that can be used without having to give them a name.([Hello] [, ] [world!] + -:: list)Is this a first class list?
Here's a picture blob:http://snap.berkeley.edu/f488ca91-2a63-1a48-83c3-ba77da29ce63
(Copy&paste with the blob: part)
Last edited by ChocolatePi (Dec. 30, 2015 19:16:58)
- Firedrake969
- Scratcher
1000+ posts
A simple way to add First Class Lists
Would a JS function like this
be a first-class function?
(function() { // stuff })();
'17 rickoid
bf97b44a7fbd33db070f6ade2b7dc549
- gdpr533f604550b2f20900645890
- Scratcher
1000+ posts
A simple way to add First Class Lists
I've used Snap! before, but I didn't know what first-class data was when I read that it supported that. I was thinking of how in Java, you could set a variable to an array using the new operator, and how you could return an array from a method without naming it.Wow, correct! That's actually how Snap! implements first-class lists!So, (empty list) is basically a way to pass list values? If I'm understanding “first class” correctly, I would like to have first class lists implemented like this: First class means being able to pass around things without having to give them a name.
There are some languages with first class functions, which means you can define functions that can be used without having to give them a name.([Hello] [, ] [world!] + -:: list)Is this a first class list?
Here's a picture blob:http://snap.berkeley.edu/f488ca91-2a63-1a48-83c3-ba77da29ce63
(Copy&paste with the blob: part)
//... System.out.println(test()[1]); //Prints 2 //... public static int[] test() { return new int[] {1,2}; }
EDIT: I got ninja'd by Firedrake969
Last edited by gdpr533f604550b2f20900645890 (Dec. 30, 2015 19:28:32)
- Discussion Forums
- » Suggestions
- » A simple way to add First Class Lists