<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="">Hi,<div class=""><br class=""></div><div class="">Mathematical correct or not: </div><div class=""><br class=""></div><div class="">in case of </div><div class=""> s1.hasPrefix(s2)</div><div class=""> (or any other containment test method) </div><div class=""><br class=""></div><div class="">s1 and s2 are just plain simple instances of String,</div><div class="">nothing more nothing less. </div><div class=""><br class=""></div><div class="">Which is interpreted by me as: </div><div class="">“test if String s1 starts with String s2”</div><div class=""><br class=""></div><div class="">which, to me, implies that one will never find an occurrence</div><div class="">of an empty string within another string,</div><div class="">for the very simple reason that an empty string</div><div class="">does not exist within another string. **</div><div class="">Ergo: “false” is the right evaluation when s2.isEmpty.</div><div class=""><br class=""></div><div class="">** In my mental model, a String is just an array of 0...n characters,</div><div class=""> like it is in most languages, very straightforward.</div><div class=""><br class=""></div><div class=""> (returning false) This is exactly the reason why NSString does that, </div><div class="">for more than 20 years, why change it?</div><div class=""><br class=""></div><div class="">AFAIK no one has complained about this for years, </div><div class="">because imho it is logically sound. </div><div class=""><br class=""></div><div class="">for a compiler this is very easy</div><div class="">all it has to do is to return False</div><div class="">when either s1 or s2 is empty.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Ted</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 19.07.2016, at 23:11, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Not that it's needed, but another +1 from me.<div class=""><br class=""></div><div class="">a.hasPrefix(p) should be true iff there exists some string x for which p+x == a. If p == "", then x := a satisfies this, so hasPrefix should return true.</div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class="">Jacob<br class=""></div></div></div></div>
<br class=""><div class="gmail_quote">On Tue, Jul 19, 2016 at 1:29 PM, Jaden Geller via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Both `hasPrefix` and `hasSuffix` are analogous to the more general `hasSubset` function, which would return `true` for the empty set.<div class=""><div class="h5"><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 19, 2016, at 12:32 PM, Bianca via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><span style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif" class="">> Empty set is a subset of all sets.</span><br style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif" class=""><br style="color:rgb(33,33,33);font-family:"helvetica neue",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. </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 <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="">
> 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" class="">swift-evolution@swift.org</a>> wrote:<br class="">
><br class="">
> 1. return “false” seems to me logically correct, because<br class="">
> 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="">
> This has worked very conveniently for NSString in ObjC for more than 20 years, why change it?<br class="">
> Do you know of cases that were problematic with this convention?<br class="">
><br class="">
><br class="">
> 2 throw a runtime error when trying to do this:<br class="">
> str.hasPrefix(“”) // also for hasSuffix, str.contains etc.<br class="">
><br class="">
> some in-line questions below.<br class="">
><br class="">
> Kind Regards<br class="">
><br class="">
> Ted<br class="">
><br class="">
><br class="">
> On 19.07.2016, at 16:31, Dave Abrahams <<a href="mailto:dabrahams@apple.com" target="_blank" class="">dabrahams@apple.com</a>> wrote:<br class="">
>><br class="">
>><br class="">
>> on Tue Jul 19 2016, "Ted F.A. van Gaalen" <<a href="http://tedvgiosdev-at-gmail.com/" target="_blank" class="">tedvgiosdev-AT-gmail.com</a>> wrote:<br class="">
>><br class="">
>>> Hi Dave<br class="">
>>><br class="">
>>> “true” ? am I going nuts ? :o)<br class="">
>>><br class="">
>>> var str = "Hello, playground"<br class="">
>>><br class="">
>>> print( str.hasPrefix("”)) // case 1 : false<br class="">
>>><br class="">
>>> print( str.hasSuffix("”)) // case 2 : false<br class="">
>>><br class="">
>>> print("" == “a” ) // case 3 : false<br class="">
>>><br class="">
>>> Currently, all cases above evaluate to “false”<br class="">
>>> i think that is correct,<br class="">
>><br class="">
>> I don't know what to tell you. It may seem intuitively correct to you,<br class="">
>> but others in the thread have laid out the reasons why it is not<br class="">
>> mathematically correct behavior.<br class="">
> Where? I couldn’t find any.<br class="">
>> One other way of rephrasing it: to get<br class="">
>> `false` for str.hasPrefix(""), you actually need special-case code in<br class="">
>> hasPrefix to check for the empty string,<br class="">
> again, maybe it should throw a run-time error instead.<br class="">
><br class="">
><br class="">
>> and the caller may well also<br class="">
>> need special-case code to handle the fact that the result is not<br class="">
>> mathematically consistent with other cases on the continuum.<br class="">
> In this context as “continuum” :<br class="">
> are you referring to “sets” or “collections” here?<br class="">
> what other cases?<br class="">
><br class="">
>> Doing<br class="">
>> things that way doesn't work in practice for real programs.<br class="">
> please explain thank you, because I see no problems at<br class="">
> all with the current NSString-like evaluation…<br class="">
> I’d put an s.isEmpty() in front of it.<br class="">
>><br class="">
>>> because:<br class="">
>>><br class="">
>>> How can an empty string be a prefix or suffix value?<br class="">
>>> as there is no empty string present in a non-empty string.<br class="">
>>><br class="">
>>> Note that if case 1 and case 2 would evaluate to “true”,<br class="">
>>> it would conflict with case 3.<br class="">
>>><br class="">
>>> Can’t imagine that case 3 should in future also result in “true”<br class="">
>>><br class="">
>>> ??<br class="">
>>><br class="">
>>> -----<br class="">
>>><br class="">
>>> Also I hope that changes to String functionality<br class="">
>>> for Swift 4 are not backward breaking changes<br class="">
>>> even the more for string handling, because Strings<br class="">
>>> are heavily used in most apps.<br class="">
>>><br class="">
>>> I am firmly convinced that all future releases of Swift<br class="">
>>> should compile Swift 3 and higher source files without<br class="">
>>> any changes 100 % flawlessly! This prevents early diminishing<br class="">
>>> of Swift’s popularity, especially with those building large<br class="">
>>> codebases using Swift.<br class="">
>>><br class="">
>>> I’ve started a thread about this a week ago,<br class="">
>>> however no one found this important enough to<br class="">
>>> share their opinions with me yet, or were too busy with<br class="">
>>> other subjects to do so.<br class="">
>>><br class="">
>>> Increasingly I have dreams, me<br class="">
>>> programming complete apps in Smalltalk<br class="">
>>> and then automagically generate<br class="">
>>> an macOS, tvOS or iOS runtime app of it.<br class="">
>>><br class="">
>>> (I have also dreams of this world becoming<br class="">
>>> a nice and peaceful placebut that is<br class="">
>>> beyond the context of this forum)<br class="">
>>><br class="">
>>> Kind Regards<br class="">
>>> TedvG<br class="">
>>><br class="">
>>> <a href="http://www.speyer.de/" rel="noreferrer" target="_blank" class="">www.speyer.de</a><br class="">
>>><br class="">
>>>> on Mon Jul 18 2016, Kevin Nattinger <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>>> wrote:<br class="">
>>>><br class="">
>>>>> I agree, true is definitely the expected behavior. In particular, it<br class="">
>>>>> seems absurd to me that `a.hasPrefix(b)` and `a.hasSuffix(b)` could be<br class="">
>>>>> false when `a == b` is true.<br class="">
>>>><br class="">
>>>> I expect to be reworking Strings for Swift 4, and this is one of the<br class="">
>>>> many things we plan to address.<br class="">
>>>><br class="">
>>>> --<br class="">
>>>> Dave<br class="">
>>>><br class="">
>>>><br class="">
>>><br class="">
>><br class="">
>> --<br class="">
>> Dave<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="">
<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/" target="_blank" class="">http://biancatamayo.me</a></div>
_______________________________________________<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" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div></div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" 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="">
<br class=""></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>