Discuss Scratch

Greg8128
Scratcher
500+ posts

split blocks

mitdk wrote:

PkmnQ wrote:

panda-wat wrote:

Nice, as long as it doesn't crash if it sees these:
(section [3] of split [a.b] on character [.]::operators) // sections 3 and up do not exist
(section [1] of split [a.b] on character [Q]::operators) // that character is not in the input
(section [1] of split [a.b.c] on character [.]::operators) // multiple of that character are in the input
(section [1] of split [a.b] on character [ab]::operators) // this does not need an explanation.
They would report this:
(section (3) of split [a.b] on character [.]::operators) // would report an empty string
(section (1) of split [a.b] on character [Q]::operators) // would report "a.b"
(section (1) of split [a.b.c] on character [.]::operators) // would report "a"
(section (1) of split [a.b] on character [ab]::operators) // would report "a.b"
And here's some extras to help you understand better:
(section (1) of split [a.ab.b] on character [ab]::operators) // would report "a."
(section (2) of split [a.ab.b] on character [.]::operators) // would report "ab"
Yes, all correct. and..

panda-wat wrote:

Nice, as long as it doesn't crash if it sees these:
(section [3] of split [a.b] on character [.]::operators) // sections 3 and up do not exist
(section [1] of split [a.b] on character [Q]::operators) // that character is not in the input
(section [1] of split [a.b.c] on character [.]::operators) // multiple of that character are in the input
(section [1] of split [a.b] on character [ab]::operators) // this does not need an explanation.
Also, the stack block, if this reporter were to be made, would have an obvious workaround like this:
add (section [] of split [] on character []::operators) to [list v]::list

Lastly, I think that this is a little too advanced for a website geared toward eight year olds. but then again:
([abs v] of ())
actually, i just seemed to think of another workaround. sorry @Greg8128 but i think i will remove the stack block.
Thanks for all the support and suggestions.
set [ v] to []
repeat (length of [])
change [ v] by (1)
add (section (::variables) of split [text] on character [ ]::operators) to [list v]

end

the difference is that the workaround is forced to parse the string once for each section while my suggested block would have needed only one pass total. Say for example that you have 10000 numbers separated by semicolons. Even taking into account that the (section of split block) could stop parsing once it reaches the needed section, and disregarding the fact that Scratch code runs slower than JS code, the workaround would take roughly 5000 times longer to accomplish the same task.

Then again this is a somewhat niche use case so it might not be worth adding.
cwkavery46304
Scratcher
29 posts

split blocks

mitdk wrote:

cwkavery46304 wrote:

mitdk wrote:

I would now like these 2 blocks to be added
(section() of split[] on character[]::operators)
and:
split [] by [] and add to [list v]::operators 
credit to Greg8128 for this idea(as you can see in the posts above)



mitdk
maybe they should move some of the opperators blocks to a new section called ‘text’ that would also have your split blocks.
I'm not sure.. we don't want to ask for too much

good point mitdk.
MartianSoil
Scratcher
100+ posts

split blocks

I don’t know if this has been mentioned yet, but what if you did

(section(1) of split[0244726382346234890] on character[8]::operators)

That would mess it up, which would it report. I assume the first one, but I feel like this would be better if it actually reported on the character number, like this:

(section() of split[] on character number[]::operators)

When you click the last input it would bring up the number keypad that is used in other operator blocks such as

((0) - (0))

EDIT: Fixed Scratchblocks. Sorry that the emojis messed up script.

Last edited by MartianSoil (Oct. 20, 2020 12:59:24)

-CloudGate-
Scratcher
1000+ posts

split blocks

there is a pretty easy workaround, and most people who need this block will find it easy to make
mitdk
Scratcher
1000+ posts

split blocks

MartianSoil wrote:

I don’t know if this has been mentioned yet, but what if you did
(section(1) of split on character:perators)

That would mess it up, which would it report. I assume the first one, but I feel like this would be better if it actually reported on the character number, like this:
(section() of split on character number:perators)
When you click the last input it would bring up the number keypad that is used in other operator blocks such as
((0) - (0))
Multiple chars being split has been mentioned before:

mitdk wrote:

If there are multiple of 1 character (say 2 periods) then you would get 3 sections. As for your other question, I got this idea from python, with the function
split(num, .)
In python, the split character disappears. I would go with that.
PkmnQ
Scratcher
1000+ posts

split blocks

-CloudGate- wrote:

there is a pretty easy workaround, and most people who need this block will find it easy to make
Does the easy workaround also work with multiple characters?
MartianSoil
Scratcher
100+ posts

split blocks

I believe if you made a costume block that calculate which letter it was and what letter you want. I would make with scratchblocks, but it was getting to complicated, so I will put it in a project.
cwkavery46304
Scratcher
29 posts

split blocks

MartianSoil wrote:

I don’t know if this has been mentioned yet, but what if you did

(section(1) of split[0244726382346234890] on character[8]::operators)

That would mess it up, which would it report. I assume the first one, but I feel like this would be better if it actually reported on the character number, like this:

(section() of split[] on character number[]::operators)

When you click the last input it would bring up the number keypad that is used in other operator blocks such as

((0) - (0))

EDIT: Fixed Scratchblocks. Sorry that the emojis messed up script.
we could make it so that it did not allow you to type a decimal point.
MapleSyrup911
Scratcher
83 posts

split blocks

I think something like this would be easier to understand for new scratchers
(split (3) characters [left v] of [Hello this is some text]::operators)//Reports "Hel"
(split (3) characters [right v] of [Hello this is some text]::operators)//Reports "ext"
mitdk
Scratcher
1000+ posts

split blocks

MapleSyrup911 wrote:

I think something like this would be easier to understand for new scratchers
(split (3) characters [left v] of [Hello this is some text]::operators)//Reports "Hel"
(split (3) characters [right v] of [Hello this is some text]::operators)//Reports "ext"
Yes, it would, but it does not solve the main problem. The block i am suggesting splits on a chosen character, not on a character #.
PkmnQ
Scratcher
1000+ posts

split blocks

There seems to be a lot of confusion over what this does, so I've made a post that can be referred to.

(section (1) of split [a.b.c] on character [.] :: operators)
This simply reports “a”. Think of it as a list, with “.” as a separator.

(section (1) of split [a..b] on character [..] :: operators)
This simply reports “a”. The word “character” is misleading.

(section (1) of split [a,b] on character [.] :: operators)
This simply reports “a,b”. It's sort of like a 1-item list.

(section (3) of split [a.b] on character [.] :: operators)
This simply reports an empty string. It acts similarly to this block:
(item ( v) of [list v] :: list)

Last edited by PkmnQ (Oct. 23, 2020 04:17:15)

awesome_guy6856
Scratcher
100+ posts

split blocks

workaround involves like 50 billion blocks and it's super complex and I hate it, so I support. However, I think the block you suggest is a little… not good. I think it would work better if it returned a list, and you could use list blocks on it. (Basically how .split() works in python)

Last edited by awesome_guy6856 (Oct. 23, 2020 18:16:15)

Greg8128
Scratcher
500+ posts

split blocks

awesome_guy6856 wrote:

workaround involves like 50 billion blocks and it's super complex and I hate it, so I support. However, I think the block you suggest is a little… not good. I think it would work better if it returned a list, and you could use list blocks on it. (Basically how .split() works in python)
Due to the way Scratch works, you would only be able to select a list to add to, which isn't quite the same as returning a new list. But I agree
mitdk
Scratcher
1000+ posts

split blocks

Greg8128 wrote:

awesome_guy6856 wrote:

workaround involves like 50 billion blocks and it's super complex and I hate it, so I support. However, I think the block you suggest is a little… not good. I think it would work better if it returned a list, and you could use list blocks on it. (Basically how .split() works in python)
Due to the way Scratch works, you would only be able to select a list to add to, which isn't quite the same as returning a new list. But I agree
Yes, I'll think of a ways to simplify.
mitdk
Scratcher
1000+ posts

split blocks

PkmnQ wrote:

There seems to be a lot of confusion over what this does, so I've made a post that can be referred to.

(section (1) of split [a.b.c] on character [.] :: operators)
This simply reports “a”. Think of it as a list, with “.” as a separator.

(section (1) of split [a..b] on character [..] :: operators)
This simply reports “a”. The word “character” is misleading.

(section (1) of split [a,b] on character [.] :: operators)
This simply reports “a,b”. It's sort of like a 1-item list.

(section (3) of split [a.b] on character [.] :: operators)
This simply reports an empty string. It acts similarly to this block:
(item ( v) of [list v] :: list)
Thanks! do you think that this would work better for the block?
(section (1) of split [a..b] on string [..] :: operators)

Last edited by mitdk (Oct. 25, 2020 21:17:48)

mitdk
Scratcher
1000+ posts

split blocks

bump
mitdk
Scratcher
1000+ posts

split blocks

bump
mitdk
Scratcher
1000+ posts

split blocks

bump
rontinn
Scratcher
85 posts

split blocks

what if something has an odd number of characters and is split into two sections?
mitdk
Scratcher
1000+ posts

split blocks

rontinn wrote:

what if something has an odd number of characters and is split into two sections?
This block splits on a character, not evenly. for more explanations/examples, look at this:

PkmnQ wrote:

There seems to be a lot of confusion over what this does, so I've made a post that can be referred to.

(section (1) of split [a.b.c] on character [.] :: operators)
This simply reports “a”. Think of it as a list, with “.” as a separator.

(section (1) of split [a..b] on character [..] :: operators)
This simply reports “a”. The word “character” is misleading.

(section (1) of split [a,b] on character [.] :: operators)
This simply reports “a,b”. It's sort of like a 1-item list.

(section (3) of split [a.b] on character [.] :: operators)
This simply reports an empty string. It acts similarly to this block:
(item ( v) of [list v] :: list)

Last edited by mitdk (Nov. 14, 2020 03:52:47)

Powered by DjangoBB