<div dir="ltr">I&#39;m not suggesting this for the standard library (or anyone&#39;s production code), but it&#39;s fun to note that there is actually a standard mathematical notation for this, and it has a corresponding Unicode character U+2223 &quot;DIVIDES&quot;: ∣<div><br></div><div><div><font face="monospace, monospace">    infix operator ∣ {}</font></div><div><font face="monospace, monospace">    func ∣&lt;I: IntegerType&gt;(lhs: I, rhs: I) -&gt; Bool {</font></div><div><font face="monospace, monospace">        return rhs % lhs == 0</font></div><div><font face="monospace, monospace">    }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    3 ∣ 12  // true</font></div><div><font face="monospace, monospace">    4 ∣ 12  // true</font></div><div><font face="monospace, monospace">    5 ∣ 12  // false</font></div></div><div><br></div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Thu, Apr 7, 2016 at 11:13 AM, Milos Rankovic via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">Thank you for giving this a thought!<span><font color="#888888"><div><br></div><div>milos</div></font></span><div><div><div><br><div><blockquote type="cite"><div>On 7 Apr 2016, at 15:13, Erica Sadun &lt;<a href="mailto:erica@ericasadun.com" target="_blank">erica@ericasadun.com</a>&gt; wrote:</div><br><div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div><br>On Apr 6, 2016, at 10:13 AM, Milos Rankovic via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">Checking for divisibility is very common:<div><br></div><div>    <span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">21</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px"> % </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">3</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px"> == </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">0</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px"> </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(203,203,203)">// true</span></div><div><br></div><div>In fact, this is such a common use of the `<span style="font-family:&#39;Source Code Pro&#39;;font-size:12px">%</span>` operator that the `<span style="font-family:&#39;Source Code Pro&#39;;font-size:12px">== </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">0</span>` side of the expression seems distracting in this use case. For quite a while now, I’ve been using a custom operator for this, which is steadily growing on me:</div><div><br></div><div>    <span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">21</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px"> </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(145,84,15)">%==</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px"> </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">3</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px"> </span><span style="color:rgb(203,203,203);font-family:&#39;Source Code Pro&#39;;font-size:12px">// true</span></div><div><br></div><div>… which also allows me to overload it for sequences:</div><div><br></div><div>    <span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">21</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px"> </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(145,84,15)">%==</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px"> [</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">7</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px">, </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(255,38,0)">3</span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px">] </span><span style="font-family:&#39;Source Code Pro&#39;;font-size:12px;color:rgb(203,203,203)">// true</span></div><div><br></div><div>(If I’m inadvertently misusing this mailing list to share such a minor idea, please tell me off so that I can learn not to do it again!)</div><div><br></div></div></div></blockquote><br></div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">While modulo checks are common, I don&#39;t think that your proposed solution (%==) enhances readability or saves typing *<b>to such extent</b>* that it vastly improves over the existing art:</div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Menlo">21 % 3 == 0</font><span> </span>reads easily from left to right, is quick to type, is understood across many languages.</div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="Menlo">21 %== 3   </font> saves a few spaces, is less immediately understandable (due to the visual overlap with `+=` and `-=`) and would be (as far as I&#39;m aware of) unique to Swift.</div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I applaud the thinking and creativity but I would not support the proposal.</div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:-webkit-standard;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">-- E</div></div></blockquote></div><br></div></div></div></div><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></blockquote></div><br></div></div>