yasl icon indicating copy to clipboard operation
yasl copied to clipboard

Add `max_splits` argument to `str.split`

Open CoffeeTableEspresso opened this issue 3 years ago • 4 comments

Currently, str.split takes two arguments: the string to split, and what to split it on. This CL adds a third argument, max_splits, that limits the number of times a string can be split.

As an example:

'a b c d'->split(' ')  # ['a', 'b', 'c', 'd']
'a b c d'->split(' ', 2)  # ['a', 'b', 'c d']

In the first version (which works today), we allow unlimited splits. In the second version (which is what this issue wants to add), we only split the string twice, even though there is a third space in it.

CoffeeTableEspresso avatar Apr 25 '21 23:04 CoffeeTableEspresso

Good day, @CoffeeTableEspresso, I would like to have a shot at this. Please could more description be given?

RandyKdev avatar Sep 24 '21 15:09 RandyKdev

Sure, updated the description to include an example of what I mean.

For actually making this change, you'll want to look in https://github.com/yasl-lang/yasl/blob/master/interpreter/str_methods.c, and change the str_split function.

Let me know if anything is unclear in the code itself, I know it's not always particularly well documented.

CoffeeTableEspresso avatar Sep 24 '21 17:09 CoffeeTableEspresso

And, you'll need to change the entry for str_split on line 77 of https://github.com/yasl-lang/yasl/blob/master/interpreter/builtins.c. It should take 3 parameters instead of 2.

CoffeeTableEspresso avatar Sep 24 '21 17:09 CoffeeTableEspresso

Ok, let me give it a shot.

RandyKdev avatar Sep 24 '21 18:09 RandyKdev

Done

CoffeeTableEspresso avatar Mar 31 '23 23:03 CoffeeTableEspresso