-
Notifications
You must be signed in to change notification settings - Fork 418
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
Should string/bytes multiplication be commutative? #17506
Comments
I have added "good first issue" on this because of ease of implementation. Before we implement this, I want to make sure that we have consensus that we want this (and that I am not missing anything as to why we don't have this today). |
I never even realize/remember we support this form of multiplication until someone mentions it once every blue moon. Is this "multiply string by integer" a feature that's found in other scripting-like languages or did we make it up? If others support it, do they support the commutative form as well? If so, I agree we should as well. If there isn't a precedent for it, I'd be inclined to deprecate it (or move it into a helper module that has to be explicitly used/included), where my main concern about it is that it's the type of feature where if the example is not as literal as the one above (say, it's |
Python does support it, and commutatively:
|
Thanks, that's good enough for me! |
Hey @e-kayrakli , can I work on this issue? |
@shubhamkmr04 -- Thanks for the interest! After checking with others offline, as well, I think we can proceed with this.
Let me know if you have any questions and if/when you have PR on this. |
Hey @e-kayrakli Thanks for the explanation, These are the changes I am have done so far:
I got some doubts too:
|
All good news! Feel free to open a draft PR even if everything is not done. We can discuss these matters under a PR. I would probably take a simpler approach in documenting this. (I also think that the documentation for string/bytes operators can use some more editing, but that's not what you should do in this PR.) For now, maybe just add "The operation is commutative.", right before the existing "For example:", and then add the reversed version in the existing code-block, and update the output, obviously.
That's a good idea. Frankly, I can do with or without the examples, but I wish string/bytes versions are consistent. And while we already have an example for the string version, let's add the same thing to the bytes version.
Ah, I have missed to add some pointers about it. First make sure that the test infrastructure is built: A bonus here is to write a single Chapel file that tests with both string and bytes types. This would involve casting all string/bytes literals to a
That's exactly right. Leave all the existing |
Added commutativity in string/bytes multiplication This PR adds commutativity in bytes and string multiplication with int. Resolves #17506 [Contributed by @shubhamkmr04, reviewed/tested/merged by @e-kayrakli] Test: - [x] full standard
Today we can do:
but we cannot do
because we don't have the overloads of these operator with symmetric arguments.
I think we should support
int*string
andint*bytes
operations, as well.The text was updated successfully, but these errors were encountered: