4 ms·
What I like about Scala is the use of () for indexing arrays. It feels like a more uniform syntax - indexing an array is conceptually like calling a function fr
by Dewie 12y ago
What I like about Scala is the use of () for indexing arrays. It feels like a more uniform syntax - indexing an array is conceptually like calling a function from int to elements of the array - and I guess it reduces parsing ambiguity w.r.t. generics.
Though apparently this couldn't be used in Rust, since they want both traits for indexing ( [] ) and calling like a function ( () ) on types that implement those respective traits.
- dbaupp 12y ago`()` is now overloadable, so one could implement that operators for arrays/vectors/slices to get indexing via ().
- eddyb 12y agoNot `map[k] = v;`, which is deal breaker.
- dbaupp 12y agoOther languages don't offer indexing sugar at all, so even minimal sugar for retrieving elements might be nice. There are however, more significant road blocks, like how to handle returning references (basically, we would be left in a similar situation to the current Index trait, which has its uses, but isn't what most indexing should do).
- eddyb 12y agoRight, that too, no first-class lvalues in Rust.
- mkl 12y agoMatlab uses () for indexing, and I find it awful - you can't tell the difference between indexing and function calls, making code much harder to understand and reason about. It can be pretty confusing for people learning, too (I teach it to undergrad engineers, and don't get a say in the language choice).