4 ms·
> How do you disambiguate that from a function call? It's now just abusing () You don't. If you apply an integer to an array, it will return an entry. To me,
by beeforpork 7y ago
> How do you disambiguate that from a function call? It's now just abusing ()
You don't. If you apply an integer to an array, it will return an entry. To me, it makes perfect sense to use a(i) instead of a[i]. In fact, in case you need some more complicated data structure to organise your data one day, you could switch to a function call for lookup without rewriting the code that uses a(i).
The question is not 'how do you disambiguate?', but 'why do you want to distinguish?' Because an array is just a special case of a function that maps an integer to something else. It is logically not different from a function with a large contiguous switch statement.
- username90 7y ago> To me, it makes perfect sense to use a(i) instead of a[i]. I disagree. Square brackets links to memory, paren just returns data. Of course you could implement the paren function to return a reference, but it makes the code a lot harder to read since that is not the normal case. See comparison: a[i] = 3; or a(i) = 3;