Perl 6 Perl 6 Lists and Arrays vivified #42

Array vs. List

> my $fruit = 'apple';
> my @array = (0, 1, $fruit);       # an Array
> @array[2] = 'cherry'; 
> say $fruit;                 
apple

> my $arrayref = [ 0, 1, $fruit ];  # an Array(ref)
> $arrayref[2] = 'cherry';
> say $fruit
apple

> my $list = @(0, 1, $fruit);       # a List
> $list[2] = 'cherry';               # list holds $fruit var
> say $fruit;   
cherry

> $list[0] = 'orange';               # error, cannot assign to 1
Copyright © 2012
http://www.pmichaud.com/2012/pres/