Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support for string multiplication (str * num) #478

Open
2 of 5 tasks
Luna-Klatzer opened this issue Jun 25, 2023 · 0 comments
Open
2 of 5 tasks

[Feature] Add support for string multiplication (str * num) #478

Luna-Klatzer opened this issue Jun 25, 2023 · 0 comments
Assignees
Labels
feature New feature or enhancement
Milestone

Comments

@Luna-Klatzer
Copy link
Member

Is there an existing proposal for this?

  • I have searched the existing issues

This feature does not exist in the latest version

  • 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 and num.
  • Add compiler optimisations for the new type of string multiplication.
  • Add warning for useless string multiplications.
@Luna-Klatzer Luna-Klatzer added the feature New feature or enhancement label Jun 25, 2023
@Luna-Klatzer Luna-Klatzer added this to the v0.11.0 milestone Jun 25, 2023
@Luna-Klatzer Luna-Klatzer self-assigned this Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
Development

No branches or pull requests

1 participant