<div dir="ltr">On Sat, Jun 18, 2016 at 4:50 PM, Michael Peternell via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> Am 17.06.2016 um 07:45 schrieb Charlie Monroe via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br>
><br>
> Motivational example:<br>
><br>
> var urlString = self.urlString<br>
> if urlString.hasPrefix("//") {<br>
> urlString = "http:" + urlString // urlString needs to be typed twice<br>
> }<br>
><br>
> While there is currently an easy way to append string using +=, there is no shortcut for prefixing a string. What I propose is adding a =+ operator for prefixing the string:<br>
><br>
> urlString =+ "http:"<br>
><br>
> Would anyone else find it useful?<br>
<br>
</span>No. What I would find useful though, is to recognize that addition is not string concatenation. There is a strong convention in mathematics that the "+" symbol should only be used for operations that are commutative. String concatenation is not commutative. (There are more conventions regarding "+", but all of them are respected by numbers, vectors, complex numbers, quaternions, or matrices - just to name a few.)<br>
<br>
I would like to have a different operator for string concatenation.</blockquote><div><br></div><div>I don't see how this would measurably improve Swift code. IIUC, much of the problem with `+` and strings arises from implicit conversions that don't happen in Swift. It's not even possible to write a generic algorithm that accidentally confuses arithmetic `+` and string concatenation `+`, since you would have to retroactively conform strings and numeric types to a nonsensical protocol of your own making.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Maybe "~~" or "++"? Now that the prefix and postfix operators for numbers ("++" and "--") are removed from Swift 3, "++" could be used for string concatenation.<br>
<br>
-Michael<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div></div>