On Fri, Jul 31, 2015 at 4:16 PM, Moritz Lenz <mor...@faui2k3.org> wrote:
> > > On 07/31/2015 03:02 PM, Gabor Szabo wrote: > >> The following code (with comments) is confusing me. >> Can someone give some explanation please? >> Specifically the difference between >> >> my @x = <a b>; >> > > It's the assignment to the Array variable that makes the Array here; < > > by itself just creates a Parcel: > > $ ./perl6-m -e 'say <a b>.^name' > Parcel > $ ./perl6-m -e 'say (my @ = <a b> ).^name' > Array > > # we can assign that array to a scalar variable and it is still and array >> my $y = @x; >> > > that's because assignment to $ isn't coercive in the same way as > assignment to @ or %. > > It just wraps things into a Scalar, which is normally invisible. > > But, you can observe the difference still> > > my @a = <a b>; > my $s = @a' > > for @a { } # two iterations > for $s { } # one iteration > > Thanks though this just shows I still don't get the whole sigil and Array thing in Perl 6. I thought you can put an array in a $ -ish variable and that will still be a real array, but now I see it is not an array. use v6; my $z = ['a', 'b', 'c']; say $z.^name; # Array for $z { say $^a; # a b c (single iteration) } say $z.elems; # 3 # assigning it to a @-thing does not convert it to a real array either: my @a = $z; say @a.^name; # Array for @a { say $^a; # a b c (single iteration) } say @a.elems; # 1 # and even say @a[0].^name; # Array for @a[0] { say $^a; # a b c (single iteration) } say @a[0].elems; # 3 # explicitly converting a fake(?) Array to an Array works... my @x = $z.Array; say @x.^name; # Array for @x { say $^a; # (3 itterations) } say @x.elems; # 3 Probably it has another name and you don't call it "fake" array, do you? Gabor