Discuss Scratch

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.
(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)
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
This would make the sprite say 1,2,3 etc. Simple, right?

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)
(all but first 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.

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

A simple way to add First Class Lists

Makes sense.

BookOwl
Scratcher
1000+ posts

A simple way to add First Class Lists

IronBit_Studios wrote:

Makes sense.
Yay.
So, is that support?

who needs signatures
IronBit_Studios
Scratcher
1000+ posts

A simple way to add First Class Lists

BookOwl wrote:

IronBit_Studios wrote:

Makes sense.
Yay.
So, is that support?
Maybe if I knew what you were suggesting?

BookOwl
Scratcher
1000+ posts

A simple way to add First Class Lists

IronBit_Studios wrote:

BookOwl wrote:

IronBit_Studios wrote:

Makes sense.
Yay.
So, is that support?
Maybe if I knew what you were suggesting?
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.

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

BookOwl wrote:

IronBit_Studios wrote:

BookOwl wrote:

IronBit_Studios wrote:

Makes sense.
Yay.
So, is that support?
Maybe if I knew what you were suggesting?
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.

Why did you say that it makes sense if you didn't know what I was suggesting?
Isn't it a workaround? If not, I read it wrong but support anyways.

BookOwl
Scratcher
1000+ posts

A simple way to add First Class Lists

IronBit_Studios wrote:

BookOwl wrote:

IronBit_Studios wrote:

BookOwl wrote:

IronBit_Studios wrote:

Makes sense.
Yay.
So, is that support?
Maybe if I knew what you were suggesting?
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.

Why did you say that it makes sense if you didn't know what I was suggesting?
Isn't it a workaround? If not, I read it wrong but support anyways.
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!

who needs signatures
IronBit_Studios
Scratcher
1000+ posts

A simple way to add First Class Lists

Yeah, support then.

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.

Last edited by Jonathan50 (July 1, 2016 23:30:26)

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

cookies are yummy
Chibi-Matoran
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?
(myVar)//This is a variable
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"
I probably will support the suggestion and it sounds helpful, but I just don't quite understand it yet.

If you see this signature while scrolling, you have been visited by ʎ++ haskal. Lazy evaluation, monads, function purity, lambdas, currying, partial application, algebraic data types, pattern matching, and typeclasses will come to you, but only if you comment, “Thanks, ʎ++ haskal” on my profile.

Cassian && ||
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.
Chibi-Matoran
Scratcher
1000+ posts

A simple way to add First Class Lists

ChocolatePi wrote:

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.
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:
([Hello] [, ] [world!] + -:: list)
Is this a first class list?

If you see this signature while scrolling, you have been visited by ʎ++ haskal. Lazy evaluation, monads, function purity, lambdas, currying, partial application, algebraic data types, pattern matching, and typeclasses will come to you, but only if you comment, “Thanks, ʎ++ haskal” on my profile.

Cassian && ||
ChocolatePi
Scratcher
1000+ posts

A simple way to add First Class Lists

Chibi-Matoran wrote:

ChocolatePi wrote:

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.
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:
([Hello] [, ] [world!] + -:: list)
Is this a first class list?
Wow, correct! That's actually how Snap! implements first-class lists!

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
(function() {
    // stuff
})();
be a first-class function?

'17 rickoid

bf97b44a7fbd33db070f6ade2b7dc549
Chibi-Matoran
Scratcher
1000+ posts

A simple way to add First Class Lists

ChocolatePi wrote:

Chibi-Matoran wrote:

ChocolatePi wrote:

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.
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:
([Hello] [, ] [world!] + -:: list)
Is this a first class list?
Wow, correct! That's actually how Snap! implements first-class lists!

Here's a picture blob:http://snap.berkeley.edu/f488ca91-2a63-1a48-83c3-ba77da29ce63

(Copy&paste with the blob: part)
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.
//...
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 Chibi-Matoran (Dec. 30, 2015 19:28:32)


If you see this signature while scrolling, you have been visited by ʎ++ haskal. Lazy evaluation, monads, function purity, lambdas, currying, partial application, algebraic data types, pattern matching, and typeclasses will come to you, but only if you comment, “Thanks, ʎ++ haskal” on my profile.

Cassian && ||
Sheep_tester
Scratcher
500+ posts

A simple way to add First Class Lists

Support.

So if I did
set [list1 v] to (empty list :: list)
set [list2 v] to (empty list :: list)
add (list1) to [list3 v]
add (list2) to [list3 v]
I would have lists inside lists, right?

The above post was most likely written by a sheep. Advertisements:

Powered by DjangoBB

Standard | Mobile