Non expert opinion here.

my $z = ['a', 'b', 'c'];

Is a real array. The difference is that is in a non-auto flattening
container (variable). If you want to iterate over it you can:

for @$z { ... } # like perl5

If you want to assign it to @ array then do the same thing @a = @$z.

If you want to assign to an array which is an element of another array:

@a = $z[0].list

or in a less documented way:

@a = $z[0]<>

The idea is that you can store an array in ether a @ or $ variable. Where
as in perl5 you could only store a reference in $ variable. The sigil
simply tells perl6 how it should behave in a given context.


LL









On Sun, Aug 2, 2015 at 2:43 PM, Gabor Szabo <ga...@szabgab.com> wrote:

>
>
> 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
>
>

Reply via email to