Front page | perl.perl6.language |
Postings from September 2002
Re: Regex query
From: Peter Haworth
September 24, 2002 07:27
Re: Regex query
Message ID: PGM.email@example.com
On 24 Sep 2002 05:21:37 -0400, Aaron Sherman wrote:
> On Tue, 2002-09-24 at 01:46, Trey Harris wrote:
> > sub push(@target is rw, *@list);
> Well, yes, but that wasn't the point. The C<*@list> will force array
> flattening, thus
> push @a, [1,2,3], 4;
> will (according to Larry's stated desire to unify arrays and references
> to arrays in terms of behavior) result in four elements getting pushed
> onto C<@a>, not two.
But the decision on how arguments get passed happens at compile time, not run
time. At that point we can tell the difference between an explicit arrayref
and a flattened array:
push @a,1,2,3; # 1 - list
push @a,(1,2,3); # 2 - list
push @a,[1,2,3]; # 3 - scalar
push @a,@b; # 4 - list
push @a,*@b; # 5 - list
push @a,\@b; # 6 - scalar
push @a,[@b]; # 7 - scalar
1 and 2 are the same; parens in a list don't have any effect, and push
receives three elements in its @list parameter. 3 is an explicit arrayref so
gets passed as a single scalar. This is a simple and obvious distinction for
the programmer to make.
4 and 5 are the same due to the *@ prototype; push receives the contents of
@b in its @list parameter. 6 is an explicit arrayref, so that's what push gets
given. I would argue that 7 is like 6, except that it copies @b's elements.
Peter Haworth firstname.lastname@example.org
Reporter: Mr Gandhi, what do you think of Western Civilization?
Gandhi: I think it would be a good idea.