<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Both `hasPrefix` and `hasSuffix` are analogous to the more general `hasSubset` function, which would return `true` for the empty set.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 19, 2016, at 12:32 PM, Bianca via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><span style="color:rgb(33,33,33);font-family:&quot;helvetica neue&quot;,helvetica,arial,sans-serif" class="">&gt; Empty set is a subset of all sets.</span><br style="color:rgb(33,33,33);font-family:&quot;helvetica neue&quot;,helvetica,arial,sans-serif" class=""><br style="color:rgb(33,33,33);font-family:&quot;helvetica neue&quot;,helvetica,arial,sans-serif" class=""><font color="#212121" face="helvetica neue, helvetica, arial, sans-serif" class="">True but all sets certainly do not _contain_ the empty set, which is what might be confusing, as the word "contains" in the context of sets implies that it's a member of the set of characters that make up a String.&nbsp;</font><div class=""><font color="#212121" face="helvetica neue, helvetica, arial, sans-serif" class=""><br class=""></font><div class="gmail_quote"><div dir="ltr" class="">On Tue, Jul 19, 2016 at 12:23 PM Charlie Monroe via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="">
&gt; On Jul 19, 2016, at 6:17 PM, Ted F.A. van Gaalen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt; 1.&nbsp; return “false”&nbsp; seems to me logically correct, because<br class="">
&gt;&nbsp; &nbsp; &nbsp;there is never an empty string in another string, and an empty string cannot contain another empty string, right?<br class="">
<br class="">
Empty set is a subset of all sets.<br class="">
<br class="">
Just like:<br class="">
<br class="">
let arr1: [String] = ["Hello", "Swift", "Evolution"]<br class="">
let arr2: [String] = []<br class="">
arr1.starts(with: arr2, isEquivalent: ==) // true<br class="">
<br class="">
&gt;&nbsp; &nbsp; This has worked very conveniently for NSString in ObjC for more than 20 years, why change it?<br class="">
&gt;&nbsp; &nbsp; Do you know of cases that were problematic with this convention?<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; 2&nbsp; throw a runtime error when trying to do this:<br class="">
&gt;&nbsp; &nbsp; str.hasPrefix(“”)&nbsp; &nbsp; &nbsp;//&nbsp; also for hasSuffix,&nbsp; str.contains etc.<br class="">
&gt;<br class="">
&gt; some in-line questions below.<br class="">
&gt;<br class="">
&gt; Kind Regards<br class="">
&gt;<br class="">
&gt; Ted<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; On 19.07.2016, at 16:31, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" target="_blank" class="">dabrahams@apple.com</a>&gt; wrote:<br class="">
&gt;&gt;<br class="">
&gt;&gt;<br class="">
&gt;&gt; on Tue Jul 19 2016, "Ted F.A. van Gaalen" &lt;<a href="http://tedvgiosdev-at-gmail.com" class="">tedvgiosdev-AT-gmail.com</a>&gt; wrote:<br class="">
&gt;&gt;<br class="">
&gt;&gt;&gt; Hi Dave<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; “true” ? am I going nuts ? :o)<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; var str = "Hello, playground"<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; print( str.hasPrefix("”)) // case 1 : false<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; print( str.hasSuffix("”)) // case 2 : false<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; print("" == “a” )&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // case 3 : false<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; Currently, all cases above evaluate to “false”<br class="">
&gt;&gt;&gt; i think that is correct,<br class="">
&gt;&gt;<br class="">
&gt;&gt; I don't know what to tell you.&nbsp; It may seem intuitively correct to you,<br class="">
&gt;&gt; but others in the thread have laid out the reasons why it is not<br class="">
&gt;&gt; mathematically correct behavior.<br class="">
&gt; Where? I couldn’t find any.<br class="">
&gt;&gt; One other way of rephrasing it: to get<br class="">
&gt;&gt; `false` for str.hasPrefix(""), you actually need special-case code in<br class="">
&gt;&gt; hasPrefix to check for the empty string,<br class="">
&gt; again, maybe it should throw a run-time error instead.<br class="">
&gt;<br class="">
&gt;<br class="">
&gt;&gt; and the caller may well also<br class="">
&gt;&gt; need special-case code to handle the fact that the result is not<br class="">
&gt;&gt; mathematically consistent with other cases on the continuum.<br class="">
&gt; In this context as “continuum” :<br class="">
&gt;&nbsp; &nbsp;are you referring to&nbsp; “sets” or “collections” here?<br class="">
&gt; what other cases?<br class="">
&gt;<br class="">
&gt;&gt; Doing<br class="">
&gt;&gt; things that way doesn't work in practice for real programs.<br class="">
&gt; please explain thank you, because I see no problems at<br class="">
&gt; all with the current NSString-like evaluation…<br class="">
&gt; I’d put an s.isEmpty() in front of it.<br class="">
&gt;&gt;<br class="">
&gt;&gt;&gt; because:<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; How can an empty string be a prefix or suffix value?<br class="">
&gt;&gt;&gt; as there is no empty string present in a non-empty string.<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; Note that if case 1 and case 2 would evaluate to “true”,<br class="">
&gt;&gt;&gt; it would conflict with case 3.<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; Can’t imagine that case 3 should in future also result in “true”<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; ??<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; -----<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; Also I hope that changes to String functionality<br class="">
&gt;&gt;&gt; for Swift 4 are not backward breaking changes<br class="">
&gt;&gt;&gt; even the more for string handling, because Strings<br class="">
&gt;&gt;&gt; are heavily used in most apps.<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; I am firmly convinced that all future releases of Swift<br class="">
&gt;&gt;&gt; should compile Swift 3 and higher source files without<br class="">
&gt;&gt;&gt; any changes 100 % flawlessly! This prevents early diminishing<br class="">
&gt;&gt;&gt; of Swift’s popularity, especially with those building large<br class="">
&gt;&gt;&gt; codebases using Swift.<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; I’ve started a thread about this a week ago,<br class="">
&gt;&gt;&gt; however no one found this important enough to<br class="">
&gt;&gt;&gt; share their opinions with me yet, or were too busy with<br class="">
&gt;&gt;&gt; other subjects to do so.<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; Increasingly I have dreams, me<br class="">
&gt;&gt;&gt; programming complete apps in Smalltalk<br class="">
&gt;&gt;&gt; and then automagically generate<br class="">
&gt;&gt;&gt; an macOS, tvOS or iOS runtime app of it.<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; (I have also dreams of this world becoming<br class="">
&gt;&gt;&gt; a nice and peaceful placebut that is<br class="">
&gt;&gt;&gt; beyond the context of this forum)<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; Kind Regards<br class="">
&gt;&gt;&gt; TedvG<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt; <a href="http://www.speyer.de/" rel="noreferrer" target="_blank" class="">www.speyer.de</a><br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;&gt;&gt; on Mon Jul 18 2016, Kevin Nattinger &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a> &lt;mailto:<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;&gt; wrote:<br class="">
&gt;&gt;&gt;&gt;<br class="">
&gt;&gt;&gt;&gt;&gt; I agree, true is definitely the expected behavior. In particular, it<br class="">
&gt;&gt;&gt;&gt;&gt; seems absurd to me that `a.hasPrefix(b)` and `a.hasSuffix(b)` could be<br class="">
&gt;&gt;&gt;&gt;&gt; false when `a == b` is true.<br class="">
&gt;&gt;&gt;&gt;<br class="">
&gt;&gt;&gt;&gt; I expect to be reworking Strings for Swift 4, and this is one of the<br class="">
&gt;&gt;&gt;&gt; many things we plan to address.<br class="">
&gt;&gt;&gt;&gt;<br class="">
&gt;&gt;&gt;&gt; --<br class="">
&gt;&gt;&gt;&gt; Dave<br class="">
&gt;&gt;&gt;&gt;<br class="">
&gt;&gt;&gt;&gt;<br class="">
&gt;&gt;&gt;<br class="">
&gt;&gt;<br class="">
&gt;&gt; --<br class="">
&gt;&gt; Dave<br class="">
&gt;<br class="">
&gt; _______________________________________________<br class="">
&gt; swift-evolution mailing list<br class="">
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div></div></div><div dir="ltr" class="">-- <br class=""></div><div data-smartmail="gmail_signature" class="">Bianca<br class=""><a href="http://biancatamayo.me/" class="">http://biancatamayo.me</a></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>