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

function signature for the "^" operator for strings #46884

Merged
merged 1 commit into from
Sep 29, 2022
Merged

function signature for the "^" operator for strings #46884

merged 1 commit into from
Sep 29, 2022

Conversation

udohjeremiah
Copy link
Contributor

@udohjeremiah udohjeremiah commented Sep 24, 2022

The returned value of this function should be shown so as to clear ambiguities on some scenarios.

As an example, it doesn't matter if the string is of length 0 or 1, the returned value will always be a string. This isn't intuitive to think of as first glance:

julia> 'a' ^ 1
"a"

julia> 'a' ^ 0
""

Since it's said no where for the function to always return a string, its best to be in the function signature. And this will clear the ambiguities as pointed above.

A great example of this is in the * operator for strings and regex:

help?> *

  *(s::Union{AbstractString, AbstractChar}, t::Union{AbstractString, AbstractChar}...) -> AbstractString

  *(s::Regex, t::Union{Regex,AbstractString,AbstractChar}) -> Regex
  *(s::Union{Regex,AbstractString,AbstractChar}, t::Regex) -> Regex

As seen above, the ^ operator should follow the same standard too!

I opened #46885 on the regex part as well, so its balanced.

@udohjeremiah udohjeremiah added the docs This change adds or pertains to documentation label Sep 24, 2022
@fredrikekre
Copy link
Member

I opened #46885 on the regex part as well, so its balanced.

It would be preferable to group multiple changes like this in the same PR (to save CI resources, and reviewer resources).

@fredrikekre fredrikekre merged commit 8e44510 into JuliaLang:master Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants