-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
More string concatenation operations? #1771
Comments
I agree in principle. But then it feels like |
The String_Char operations definitely should be added and I do think that the concatenation of |
Don't lose faith in the mathematical purity Stefan! You were the one that originally convinced me when I found this old mailing list thread. But on a more serious note, I was a bit confused when I first came from Python and found the inoperable "string " + "string." Perhaps we should throw a more useful warning ("try the '*' command instead. :)") instead of a method not found. And if I wanted to multiply the ASCII value of two characters, I would think int('a') * int('b') to be more logical ... unless you wanted to stay within Uint8 space that is. |
I could definitely see |
I personally see a |
For What might make sense is restricting arithmetic operations on |
Where does |
It doesn't at the moment, but it's by analogy to [1] http://acl.ldc.upenn.edu/J/J99/J99-4004.pdf |
I like this change. Having |
Ok, I'm sold then. Will change it. |
Spurred by #1771. The one I really wanted to get rid of was Char+Char but that's used by iteration of Char ranges, e.g. here: https://github.com/JuliaLang/julia/blob/63dd47153097c68643dd3462656a6c74358d04e3/base/intfuncs.jl#L220 In order to get rid of that usage, the way Range iteration works would need to be changed. Currently it's a bit odd that 'a':'z' is a Range of Chars, while 'a':1:'z' is a Range of Ints. Maybe the step type of a Range shouldn't need to be the same as the start type?
I didn't know about alternation.
|
Two arguments for using |
See also #2301 for some leisurely reading on this subject. |
Our use of |
@StefanKarpinski So essentially you're saying |
The direct sum is not a algebraic operation the way addition or multiplication are. String concatenation is the algebraic operation for the monoid of strings (under concatenation) and is commonly written mathematically as juxtaposition or multiplication. It does still seem slightly sketchy to me because it's not what one commonly thinks of as multiplication. |
AFAIK the monoid binary operator does not have a canonical representation: I have seen a star, a dot, an x and an empty circle used for this purpose. To me, it looks like you just choose to overload |
I'm not sure why you're talking about this like I'm super gung-ho about using |
One option for an entirely new operator would be |
I prefer the |
I liked the juxtaposition syntax too but people found |
Here is a comparison table from Wikipedia with different string concatenation syntaxes. I personally prefer the "Hello, " ~ "World!" |
|
Yes, but it is only used as an unary operator, so there are no conflicts. |
No, it's also a binary operator now and is parsed as a call to the |
Ah, I was not aware that change had already been made. But in either case, binary |
@johnmyleswhite – is that being used in GLM, etc.? |
Yes, it's used in GLM and DataFrames provides a definition for |
I am also not quite comfortable using I am for a solution that uses a dedicated symbol for concatenation of sequences (vectors, strings, etc). If we run out of single-character symbols, we may consider compound symbols, such as |
I suppose |
There was also the juxtaposition approach, which I rather liked. |
That was nice, but a more generic sequence concatenation operator might be useful. Adding juxtaposition would give us four syntaxes for concatenating strings ( |
If we went with juxtaposition, we would remove |
I'm going to advocate the relaxation of absolute mathematical correctness for one exception - the concatenation of strings. Please can we just use Also, I guarantee that developers who are used to using
which can lead to inhomogeneous (in the sense that some people do this, others don't) code bases. I think this defeats the purpose of having 100% algebraically sound operators in the first place. |
I would consider |
Would it also be used for more general sequence concatenation? |
Dart completely removed their string concatenation operator (it was FWIW, my feeling is that using |
Thanks for those links, @nalimilan – always helpful to see what other languages are doing. |
I managed to find a working version of the "dart puzzlers" link on the way back machine: http://web.archive.org/web/20130125055347/http://www.dartlang.org/articles/puzzlers/chapter-2.html |
TIL that Java translates unicode escapes before parsing. That's the worst thing I've heard in a long time. |
I find Dart's argument that people should be using IOBuffer instead of string concatenation pretty compelling. |
Yeah, it's a pretty solid argument to get rid of the string concatenation operator altogether. There are, however, situations where you're building up a small string and you just want to do |
Yes, it should be easy to do string concatenation at least when speed is On Fri, Mar 14, 2014 at 3:50 PM, Stefan Karpinski
|
Using That being said, I found that |
I agre with @lindahua: we've already got |
It's interesting to note that the way julia works, the performance of repeated application of a binary string concatenation operator is not really a problem, since we can define But as a lisper, my preference for |
I have to say, it surely wouldn't be the end of the world, but I honestly fail to see what would be the advantage of removing As an aside, I went through this thread again and I realized that, despite the general consensus, we still have |
Yes, I greatly dislike |
Where? I can't spot this in the code. I also tried removing |
I was a little surprised by the following:
Should these be added? I'm assuming that promoting Char's to strings would be a bad idea in general, but this case seems like one worth accounting for.
The text was updated successfully, but these errors were encountered: