<div dir="ltr">> <span style="font-family:'trebuchet ms',sans-serif;font-size:12.8px">I think this is a very particular case </span><div><font face="trebuchet ms, sans-serif"><span style="font-size:12.8px"><br></span></font></div><div><font face="trebuchet ms, sans-serif"><span style="font-size:12.8px">I disagree. Swift has the concept of a range all over the place and this is a fundamental range operation. </span></font></div><div><br></div><div><div><font face="trebuchet ms, sans-serif"><span style="font-size:12.8px">> </span></font><span style="font-family:'trebuchet ms',sans-serif;font-size:12.8px"> As you pointed out this already can be implemented using resources already available in the language when needed.</span></div><div><font face="trebuchet ms, sans-serif"><span style="font-size:12.8px"><br></span></font></div><div><font face="trebuchet ms, sans-serif"><span style="font-size:12.8px">Right. A lot of things in the standard library can be implemented using resources already available, it's about the ergonomics.<br></span></font><div><span style="font-family:'trebuchet ms',sans-serif;font-size:12.8px"><br></span></div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 21, 2016 at 1:44 PM, Leonardo Pessoa <span dir="ltr"><<a href="mailto:me@lmpessoa.com" target="_blank">me@lmpessoa.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif">Adam, I think this is a very particular case and not something that needs to be added to the language. As you pointed out this already can be implemented using resources already available in the language when needed.</div></div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><img src="https://docs.google.com/uc?export=download&id=0BynK4d4SfQPuNnFzckZaLWxYejA&revid=0BynK4d4SfQPuWmcwZENNT0UyVWE2bEJETm9HZ05zMGdadHRzPQ"><br></div></div></div></div></div></div></div>
<br><div class="gmail_quote"><div><div class="h5">On 21 May 2016 at 17:22, Adam Nemecek via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>Hello, </div><div><br></div><div>I think that Swift could use the 'double modulo' operator which is for example in CoffeeScript (some discussion can be found here <a href="https://github.com/jashkenas/coffeescript/issues/1971" target="_blank">https://github.com/jashkenas/coffeescript/issues/1971</a>).</div><div><br></div><div>This operator, unlike normal modulo, takes sign from the divisor, not the dividend e.g. -10 % 3 == -1, but -10 %% 3 == 2.</div><div><br></div><div>In practice, this operator is useful for 'cyclical' indexing. For example, it would be useful for calculating the real index into a collection when we are using an index outside of the range of valid indices and could be used to index into a collection using a negative index à la Python and Ruby (where [1,2,3,4][-1] == 4).</div><div><br></div><div><br></div><div>The implementation would probably be something along these lines:</div><div><br></div><div>infix operator %% {</div><div> associativity left</div><div> precedence 150</div><div>}</div><div><br></div><div>func %%<T: IntegerArithmeticType>(lhs:T, rhs:T) -> T {</div><div> return (lhs % rhs + rhs) % rhs</div><div>}</div><div><br></div><div>If accepted, this could be later incorporated into a method or operator that works directly with collections using their count property. </div><div>Maybe the syntax could be something like [1,2,3,4] %% -1 == 4.</div><div><br></div><div>Ideas, suggestions?</div></div>
<br></div></div>_______________________________________________<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>
</blockquote></div><br></div>