David Green wrote: > Jon Lang wrote: >> Would it be reasonable to allow hashes to use .[] syntax as something >> of a shortcut for ".iterator in list context", thus allowing >> autosorted hashes to partake of the same sort of dual cardinal/ordinal >> lookup capabilities that lists with user-defined array indices have? > > I thought it already did, but apparently it's something that we discussed > that didn't actually make it into S09. I agree that .[] should apply to > hashes just as .{} can apply to arrays. The hashes don't even need to be > sorted -- %h[$n] would basically be a shorter way of saying > @(%h.values)[$n], in whatever order .values would give you.
I believe that the order that .values (or is that :v?) would give you is determined by .iterator - which, if I'm understanding things correctly, means that any use of :v, or :k, :p, or :kv, for that matter, would autosort the hash (specifically, its keys). Or am I reading too much into autosorting? Bear in mind that keys are not necessarily sortable, let alone autosorted. For instance, consider a hash that stores values keyed by complex numbers: since there's no way to determine .before or .after when comparing two complex numbers, there's no way to sort them - which necessarily means that the order of :v is arbitrary, making %h[0] arbitrary as well. This is why I was suggesting that it be limited to autosorted hashes: it's analogous to how @a{'x'} is only accessible if you've actually defined "keys" (technically, user-defined indices) for @a. -- Jonathan "Dataweaver" Lang