Re: Fwd: [november] Re: arrays and arrays ref question

2008-10-31 Thread Carl Mäsak
Guy (), Carl (), Moritz ():
  for @($ar) { ... }

 This would arguably be the nicest variant.

Well, actually, by this I meant all three variants that Moritz suggested. :)

  for @$ar { ... }
  or even
  for @ $ar { ... }
  or
  for @($ar) { ... }

Guy ():
 for ( @$ar ) { ... }

 ?

That's Moritz' first suggestion, but with a pair of unnecessary
parentheses thrown in. :)

Larry (), Carl ():
: All I know is that `for $ar.elems { ... }` used to work for this case.
: It doesn't seem to work anymore.
:
: Time to file a ticket, methinks.

Er, .elems is always supposed to return a number.  Maybe you want
.values there instead, though that doesn't work either.  :)

Yes, .values. Sorry about the confusion. (With all the shortcomings of
the name length, it doesn't invite confusion about whether a number
or a list of things is returned, as elems and values might. That
said, I've only used either method a handful times, so maybe it's just
a question of language acquisition.)

// Carl


Fwd: [november] Re: arrays and arrays ref question

2008-10-31 Thread Илья
So, I have found workaround for now:
 my $ar = [1,2,3]; loop ( my $i = 0; $i  $ar.elems; $i++ ) { $ar[$i].say }
1
2
3


2008/10/30 Илья [EMAIL PROTECTED]:
 I have found one:
 my $ar = [1,2,3]; my $i = 0; while $i  $ar.elems {say $ar[$i]; $i++ };
 1
 2
 3


 2008/10/30 Carl Mäsak [EMAIL PROTECTED]:
 Timothy ():
 my $r = 1 2 3; for $r - $t { say $t };

 Which revision of Rakudo are you running? In my r32239, it outputs 1
 2 3 on the same line (i.e. it doesn't iterate over each element).

 // Carl