Jonathan Scott Duff wrote: > Or perhaps > > for 0...@foo.end -> $k { ... } > > @foo.keys may not be what the user wanted if @foo is a sparse array.
IIRC, you have to explicitly ask for the custom index in order to get "sparse array" keys. By design, the normal index is never sparse; only the custom index. That said, a case could be made that the "custom index" rules as currently presented are too restrictive to implement sparse arrays. In particular, the fact that you must map the custom index to the standard index when the array is first created, and that you are not permitted to adjust things later on, kills much of the power inherent in sparse arrays. To implement a sparse array, I'd recommend using hashes. In particular, allow hashes that have sortable keys to be able to access them "by number" as well as "by name" - E.g.: my %x = { 'b' => 2, 'c' => 3 } say %x[0]; # same as say %x<b> %x<a> = 1; say %x[0]; #same as say %x<a> -- Jonathan "Dataweaver" Lang