-
-
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
one
for AbstractString
#19536
Comments
Multiplication is the string concatenation operator because concatenation is not commutative, whereas Given that, defining Defining |
Isn't multiplication usually commutative also? |
Often not. |
Addition doesn't have to be commutative either. Multiplication can be commutative. This just seems confusing to me. After reading through some of #11030 I can see arguments for not having any kind of operator that does string concatenation, but I don't see why * is chosen over +. But if one of these is included in the language I think there should be an appropriate |
The discussion about using
Thanks. |
our Strings should be the Free Monoid over all characters. Should it further Maybe it is more natural to have
|
Let's go ahead and do this since we're still using |
What is the appropriate place in Base for such a definition? |
This seems like a pun and more often than not sending |
Right, that's my point. This makes sense as long as we're using |
From discussion in JuliaLang#19536
I agree this makes it even clearer that we should move away from |
Fixed by #19548 |
I actually had a use case just today for "one" being "" |
The PR has been merged into master so if you check out master branch it should work out for you. Otherwise you'll have to wait for next release. |
Writing them one by one to an IOBuffer should be much more efficient I think (although perhaps less convenient). |
You can just call julia> a = [randstring(10) for i = 1:1000];
julia> using BenchmarkTools
julia> @benchmark join($a)
BenchmarkTools.Trial:
memory estimate: 13.13 kb
allocs estimate: 16
--------------
minimum time: 54.150 μs (0.00% GC)
median time: 56.809 μs (0.00% GC)
mean time: 57.813 μs (0.28% GC)
maximum time: 1.708 ms (94.77% GC)
--------------
samples: 10000
evals/sample: 1
time tolerance: 5.00%
memory tolerance: 1.00%
julia> @benchmark prod($a)
BenchmarkTools.Trial:
memory estimate: 4.87 mb
allocs estimate: 999
--------------
minimum time: 620.688 μs (0.00% GC)
median time: 1.592 ms (0.00% GC)
mean time: 1.855 ms (29.36% GC)
maximum time: 6.105 ms (82.00% GC)
--------------
samples: 2684
evals/sample: 1
time tolerance: 5.00%
memory tolerance: 1.00% |
I noticed you can do something like
but you might get an error if you try
Why was multiplication decided to be the operator on strings which appends them together? Wouldn't addition make more sense?
What do you guys think of introducing
since "zero" is often defined as a + 0 = a, and "one" is defined as a * 1 = 1. This zero then makes sense for the way multiplication is defined for Strings
The text was updated successfully, but these errors were encountered: