So I was writing a Wiki article on casting, and while researching how lists are cast, found out some awesome stuff I though I should share with the advanced community to see how they feel.
It turns out the Scratch team apparently put a lot of thought into the casting rules, as they are simple and make a lot of sense.
If you forgot what casting is, look at the Wiki article I was making: wiki.scratch.mit.edu/wiki/Casting
Casting to strings
• If all items of the list are one character long, the characters are concatenated
[a, b, c] => "abc"
• If one or more of the items have many letters, they are concatenaed with a space in between:
[a, cool, article] => "a cool article"
Casting to numbers
This bit is even more interesting:
•Empty list casts to 0:
[] => 0
•A list full of single digits and up to 1 decimal point are concatenated to a number:
[3, ., 1, 4] => 3.14
•A list with one or more multicharacter items is cast to 0 if the first item is a string or non-digit character, or the first item if not:
[12, hi] => 12
[hi, there] => 0
Last edited by Hardmath123 (2012-03-30 06:55:53)
Offline
That is amazing, particularly casting a list to a string. I did not know this.
I can tweak the toy shell project I was writing, now...
Offline
This is so very interesting!
I can only hope that whoever takes care of 2.0 remembers to add these details back in, because some of my projects already make use of them
Offline
i personally don't like this 'hidden features' in scratch. a lot other 'features' like this are the order of broadcasting (check the wiki) are pretty confusing, nontrivial, and not very beginner friendly.
well, my opinion
Offline