On Tuesday 23 April 2013 10:46:15 Graydon Hoare wrote: > On 23/04/2013 8:53 AM, Diggory Hardy wrote: > > I suspect (please correct me if I'm wrong) that if it wasn't for C and x86 > > compatibility then most people would fall into two categories: don't > > know/don't care, and prefer F-division. It's one of those little things > > like tau vs. pi which would have been less confusing if we'd started off > > on the other foot to start with. > > And IP addresses would have been 64 or 128bit from the start, there > would only be one endianness, and so forth ... yes, sure. But we don't > cast off the weight of the past so easily, and I do not think this is > something it's wise to fiddle with. > > A very widely-applied design choice in rust is that the basic types are > machine-sized and the arithmetic operations on them are (as close as > reasonable to) machine operations. The machine operation is remainder. > > Moreover, it's not "just C and x86". This same choice is taken (more or > less) by PowerPC, LLVM, C++, C#, Java, D, Go, JS, Scala, Ocaml, etc. etc. > > The path we've taken here is to admit _two_ operation-pairs, div/mod and > quot/rem. This path is taken by several languages and specs (Scheme, > Common Lisp, Ruby, Smalltalk, SML, Prolog, Haskell, Ada, and ISO 10967 > and IEEE 754). The work for this landed last week: > > https://github.com/mozilla/rust/pull/5990 > https://github.com/mozilla/rust/pull/6013 > https://github.com/mozilla/rust/issues/4565 > https://github.com/mozilla/rust/issues/4917 > > (Phew! This must really be the week for integer division!) > > The only remaining thing to struggle with is "which of the two > operation-pairs to assign the / and % symbols to", in the > operator-overloading sense. For this, we've gone with quot/rem, as in > the other languages above, and in keeping with the design preference > above. You have to call .mod() or .div() to get the other operators. > > It does mean there's a bit of a footgun surrounding the symbols / and % > specifically, on signed integer types. I would not be at all opposed to > adding a lint flag to calls-to-/-and-%-on-signed-integer-types, such > that you could trap them all. As with many things here, the design space > includes a variety of (sensible) preferences.
Wow, what a big post! Sorry, looks like I've missed far too much of the past discussion. (And I'm a little surprised at your patience!) I for one am happy so long as arr[ind.mod(z)] is possible (though arr[ind mod z] would be neater), and this is covered somewhere in the documentation. _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev