Kipper
Kipper copied to clipboard
[Feature] Add support for string multiplication (`str` * `num`)
Is there an existing proposal for this?
- [X] I have searched the existing issues
This feature does not exist in the latest version
- [X] I am using the latest version
Proposal
Add support for the Python-like syntax of multiplying strings a number of times.
For example:
var base: str = "x";
var repetitions: num = 5;
var result: str = base * repetitions;
print(result); // -> "xxxxx"
This would remove the need of writing a custom loop manually concatenating each string and allow for better compiler optimisations, where the compiler could simply/stupidly optimise it down to the following:
base + base + base + base + base
In case the amount of repetitions becomes too large, the following method could be used instead to save up on file size (In JavaScript/TypeScript compatible environments):
base.repeat(5);
Exact behaviour / changes you want
- [ ] Add support for arithmetic expressions between the type
str
andnum
. - [ ] Add compiler optimisations for the new type of string multiplication.
- [ ] Add warning for useless string multiplications.