Forum Discussion
EnTerr
11 years agoRoku Guru
"TheEndless" wrote:"EnTerr" wrote:
... what you call "indexers" but looking forward to hear more
... I used "indexer" in the C# sense. What would you call them?
Umm... i would have said "[ ] operator", i suppose. Or "index accessor". A mouthful, i know. I did not know they named it "indexer" in C# world. But now that i heard it, i like it - it's shorter.
What confused me is that you used the term in particular way, implying only numerical indexing:
"TheEndless" wrote:But this is also an "indexer" - A["foo"]. The use of [ ] is, as we know, the AA's bread and butter.
Count() is available for AAs now. Indexers are also available (i.e., AA[1])
The behavior you mention - if i got it right - was something like "ordinal indexing" (i.e. looking up value in AA by a number in some arbitrary order lineup). I wondering if there is some twisted way to get that by forcing particular interface call but come with nothing.
Side bar: this btw is different from allowing non-string keys in an AA. In some other languages one can do things like - example in Python:
>>> hash = {'a': 1, 1: True, False: [1], (1e9, 'foo'): {} }
>>> hash
{'a': 1, 1: True, (1000000000.0, 'foo'): {}, False: [1]}
>>> hash['a']
1
>>> hash[1]
True
>>> hash[1e9, 'foo']
{}
So it seems almost anything can be used as key there, also do mix&match. But not quite everything - only immutable objects are allowed: strings, numbers, tuples (but no lists), frozen-sets (but no sets or dictionaries). It can be useful but questionable due to complications (both as implementation and use).