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

string division: "pre"\"prefix" => "fix", "suffix"/"fix" => "suf". #13411

Closed
wants to merge 1 commit into from

Conversation

StefanKarpinski
Copy link
Member

I realized that writing string concatenation as * allows you to naturally use \ to strip prefixes from strings and / to strip suffixes from them, which is kind of cute.

@JeffBezanson
Copy link
Member

Is it April 1st already?

@StefanKarpinski
Copy link
Member Author

Nope. This is mathematically sound. Try doing this with minus.

@toivoh
Copy link
Contributor

toivoh commented Oct 2, 2015

Could be useful. Agree that it's consistent.

@JeffBezanson
Copy link
Member

I also agree it's consistent, but I didn't think we wanted to double down on using arithmetic operators on strings.

@ScottPJones
Copy link
Contributor

Also - why in Base, when these could perfectly well go into a package, for anybody who thinks they might be useful?

@carnaval
Copy link
Contributor

carnaval commented Oct 2, 2015

mod(x::String,y::String) = replace(x, y, "") also ?

@GunnarFarneback
Copy link
Contributor

This does seem like a rather marginal use to occupy an operator for. I'd prefer to have it undefined in Base so I can keep mapping / to split in my own code without warnings.

@StefanKarpinski
Copy link
Member Author

We should either stop using * for string concatenation or we should "double down". The point of this PR is that it occurred to me that viewing string concatenation mathematically does suggest a consistent larger vocabulary. Whether we want to use that vocabulary or not is a different question. Take this PR as food for thought.

@StefanKarpinski
Copy link
Member Author

I think the saner alternative here is probably to keep in mind that there's an algebraic structure to strings and regexes but not use arithmetic ops for it.

@pabloferz
Copy link
Contributor

https://en.wikipedia.org/wiki/String_operations#Right_quotient

@StefanKarpinski
Copy link
Member Author

Yes, this is not a totally made up operation – the notation even matches what's used in academic literature (which is why I chose * for string concatenation in the first place). I find it strange that the operation produces "" when the suffix/prefix doesn't match. I wonder what the rationale for that is.

@toivoh
Copy link
Contributor

toivoh commented Jan 26, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants