3 ms·
> People are right, the function call really is doing something different than an array index. What is fundamentally different?
by monocasa 7y ago
> People are right, the function call really is doing something different than an array index.
What is fundamentally different?
- monocasa 7y agoI mean, really? Isn't the whole point of the STL to paper over those differences and supply functions with similar semantics for those kind of accesses regardless of the data structure? About the only reason I can see for array access syntax existing is that in the days before optimizing compilers, people would have lost their mind if array access called into a function each time (with good reason). It took manual programmer intervention to hint what compilers couldn't cleanly infer themselves. We don't need that anymore.
- ben509 7y agoOne is looking up a value, while the other is (in most of these languages) executing a subroutine. While they are mathematically equivalent, in these languages they are doing different things. Function application and array access are two different concepts the symbols are trying to convey to a programmer. This is why, e.g., in Haskell where a string is literally a list of characters, they nevertheless have a different syntax for the two.
- monocasa 7y agoI mean, Haskell literally defines array access in terms of a function. > Haskell provides indexable arrays, which may be thought of as functions whose domains are isomorphic to contiguous subsets of the integers. https://www.haskell.org/onlinereport/haskell2010/haskellch14.html https://www.haskell.org/onlinereport/haskell2010/haskellch14... The fact that strings are different seems to have more to do with the ergonomics of strings rather than arrays.