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