I'm a relative beginner at perl6, but pretty good with perl5 (and C
and a few others), so I read
"for 0...@foo.elems"
as saying "Give me a list with one item longer then @foo", not "give
me the indexes of @foo". I can see users being tripped up by the old
problem of "we start counting at 0 and not at 1", which is more at the
root of what you're seeing. If perl6 started at 1 then you'd write

for 1...@foo.elems -> $k { do_something($k,@foo[$k]) } # wrong in this universe
for 0..(@foo.elems-1) -> $k { do_something($k,@foo[$k]) } # works

perl4-perl5.8 or so had a variable that let you change the starting
index for arrays, so you could actually make the above work. But then
everyone who'd re-arranged their brains to start counting at 0, and
written code that has a starting index of 0, would have problems.

>for @foo.values -> $k { do_something($k,@foo[$k]) }

try @foo.keys instead!

> But I point out that the earlier code sample was given to me on IRC at
> #perl6. If one of the current developers can make that mistake, other users
> will too. I cannot say whether it makes sense to alter the language because
> of this.

Changing the meaning of "elems" to mean anything other then the number
of elements seems likely to cause even more confusion!

I seem to recall one of the synopses discussing the replacement for
p5s "$#foo" to get the last index of foo, but I don't remember where.

Reply via email to