<div dir="ltr">To the question of whether any given string has the empty string as prefix: yes it does. This is a correct answer, and returning true is a correct behaviour.<div><br></div><div>To the question of how many times the empty string occurs in a string: yes, this can be infinite. "a" == "a" + "" == "a" + "" + "" == "a" + "" + "" + "" == "a" + "" + "" + "" + "" == ... etc.. Concatenating an empty string, like adding zero or multiplying by zero for a numerical value, can be done infinitely many times without making a difference.</div><div><br></div><div>However, there's correctness and convenience. For example, every integer can be expressed as a multiple of prime factors. 1 is technically a prime number - it's divisible by 1 and itself - but for convenience we say it isn't a prime number, because if it isn't, every integer can be expressed uniquely as a multiple of prime factors, whereas if it is, there are an infinite number of such expressions for each integer.</div><div><br></div><div>There may be many algorithms which rely on an empty prefix returning false. If hasPrefix and hasSuffix are corrected, those algorithms should be altered to recognise that correction. For example, if breaking up a string using the empty string as a separator, it seems sensible that the sequence of substrings would never contain consecutive empty strings.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 20, 2016 at 11:58 PM, Xiaodi Wu via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'd run this by someone who actually knows math, but afaik there are finitely many empty strings in any given string.<br><br>How many e's are in any given string? (Ignoring Unicode issues for now,) for each index in the string's indices, form a substring one character in length starting at that index and compare the value of that substring to e.<br><br>How many empty strings are in any given string? For each index in the string's indices, form a substring zero characters in length starting at that index and compare the value of that substring to an empty string.<div class="HOEnZb"><div class="h5"><br><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 20, 2016 at 17:35 Guillaume Lessard <<a href="mailto:glessard@tffenterprises.com" target="_blank">glessard@tffenterprises.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On 20 juil. 2016, at 14:21, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> wrote:<br>
><br>
> Doesn't your second argument undermine your first? If it's a trivial solution and one rarely ever considers empty strings when invoking `hasPrefix`, then returning the technically correct result must be a trivial departure in behavior.<br>
<br>
I specifically used an example where the trivial solution (y=0 instead of y=exp(x)) is a pitfall.<br>
<br>
How many empty strings are contained in any given string?<br>
If the answer is infinitely many, it sounds like a pitfall to me.<br>
<br>
Cheers,<br>
Guillaume Lessard<br>
<br>
</blockquote></div>
</div></div><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>
<br></blockquote></div><br></div>