4 ms·
Re 1, 6 & 7, as we've discussed before: languages that do away with the () vs. [] distinction don't have the same restrictions as Rust, e.g. Scala doesn't have
by dbaupp 12y ago
Re 1, 6 & 7, as we've discussed before: languages that do away with the () vs. [] distinction don't have the same restrictions as Rust, e.g. Scala doesn't have explicit addresses for objects, meaning `&x[i]` in Rust (get the address of the `i`th element) has no first-class equivalent in it. It isn't possible to implement this by just overloading `()` without introducing dramatic new language features.
On this note,
They overloaded their [] operator to do two completely different things,
depending on whether there is an & in front.
is entirely wrong: `x[i]` is literally equivalent to `x.index(i)` or `x.index_mut(i)` depending on mutability, so the `&x[i]` form is the same as `&x.index(i)`, and `&` is a no-op. There's no special magic other than a slightly subtle desugaring.
No Rust dev is proud that there's no overloading... that sentence doesn't even make sense, as every operator can be overloaded, including the () call syntax.
Now I agree that there's often room for improvement in designs, but hammering on a relatively minor syntactic point (especially one that follows many, many other languages) for months seemingly without understanding the current design and the reasons for it is quite tiresome.
- frowaway001 12y ago> It isn't possible to implement this by just overloading `()` without introducing dramatic new language features. Yes, that's understood, and I suggested one possible approach multiple times already. Even if there wouldn't be an easy solution ... would this requirement be important enough to wreck the whole language? I don't believe it. It's not like the situation is "we did X here and caused issue Y over there" ... the issues are all over the place,and the cost/benefit ratio is completely off. > is entirely wrong It's tongue-in-cheek, I think we all know what's going on behind the scenes. Another example is x[3] = 42 vs. x[3]. x[] does completely different things here, and it would be an issue if people wanted to use the same method, but thankfully, no one is proposing that. > No Rust dev is proud that there's no overloading... that sentence doesn't even make sense, as every operator can be overloaded, including the () call syntax. I referred to method overloading.