Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread John M. Dlugosz
You're assuming he's using an instance of the built-in Array class. I would think one reason for implementing your own class that "does Positional" is to do something out of the ordinary. So what exactly does Positional promise? I think it should be as general as possible, and avoid thinking

Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread Jon Lang
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 c

Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread yary
> Is it still a global in Perl 6? It's not even global in perl5.10. perldoc says: As of release 5 of Perl, assignment to $[ is treated as a compiler directive, and cannot influence the behavior of any other file. (That's why you can only

Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread Jonathan Scott Duff
On Tue, May 26, 2009 at 9:03 PM, Patrick R. Michaud wrote: > On Tue, May 26, 2009 at 06:43:40PM -0500, John M. Dlugosz wrote: > > Daniel Carrera daniel.carrera-at-theingots.org |Perl 6| wrote: > >> The following construction doesn't do what a user might expect: > >> > >> for 0...@foo.elems -> $k {

Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread Jon Lang
On Wed, May 27, 2009 at 7:05 AM, John Macdonald wrote: > On Tue, May 26, 2009 at 04:38:21PM -0700, yary wrote: >> 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

Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread John Macdonald
On Tue, May 26, 2009 at 04:38:21PM -0700, yary wrote: > 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 startin

Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread Mark J. Reed
I don't see how you could interpret the name "elems" as something returning "index of the last element". If your IRC interlocutor confused @foo.elems with $#foo, then it seems more likely that they were confused about the semantics of $#foo than of .elems , whose p5 equivalent is just scalar(@foo

Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread Daniel Carrera
Patrick R. Michaud wrote: An even cleaner shortcut might be to use ^...@foo instead of ^...@foo.elems: for ^...@foo -> $k { do_something($k, @foo[$k]) } Somewhat clearer could be: for @foo.keys -> $k { do_something($k, @foo[$k]) } And some may prefer: for @foo.kv -> $k, $v { do_s

Re: Unexpected behaviour with @foo.elems

2009-05-27 Thread Daniel Carrera
yary wrote: 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". But a Perl non-beginner did make that mistake. The problem is that it

Re: Unexpected behaviour with @foo.elems

2009-05-26 Thread Patrick R. Michaud
On Tue, May 26, 2009 at 06:43:40PM -0500, John M. Dlugosz wrote: > Daniel Carrera daniel.carrera-at-theingots.org |Perl 6| wrote: >> The following construction doesn't do what a user might expect: >> >> for 0...@foo.elems -> $k { do_something($k,@foo[$k]) } > > Write ^...@foo.elems as a shortcut of

Re: Unexpected behaviour with @foo.elems

2009-05-26 Thread John M. Dlugosz
Daniel Carrera daniel.carrera-at-theingots.org |Perl 6| wrote: Hello, The following construction doesn't do what a user might expect: for 0...@foo.elems -> $k { do_something($k,@foo[$k]) } Obviously, the intention is to step through every key/value in @foo. Buf @f...@foo.elems] does not exis

Re: Unexpected behaviour with @foo.elems

2009-05-26 Thread yary
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

Unexpected behaviour with @foo.elems

2009-05-26 Thread Daniel Carrera
Hello, The following construction doesn't do what a user might expect: for 0...@foo.elems -> $k { do_something($k,@foo[$k]) } Obviously, the intention is to step through every key/value in @foo. Buf @f...@foo.elems] does not exist. If @foo = (1,2,3); then @foo.elems is 3, and @foo[3] is unde