syntax @

Documentation for syntax @, assembled from the following types:

language documentation Lists, Sequences, and Arrays

From Lists, Sequences, and Arrays

(Lists, Sequences, and Arrays) sigil @

Variables in Perl 6 whose names bear the @ sigil are expected to contain some sort of list-like object. Of course, other variables may also contain these objects, but @-sigiled variables always do, and are expected to act the part.

By default, when you assign a List to an @-sigiled variable, you create an Array. Those are described below. If, instead you want to put an actual List into an @-sigiled variable, you can use binding with := instead.

my @a := 123;

One of the ways @-sigiled variables act like lists is by always supporting positional subscripting. Anything bound to a @-sigiled value must support the Positional role which guarantees this:

my @a := 1# Type check failed in binding; expected Positional but got Int 

declarator state

From state

(state) variable @

Similar to the $ variable, there is also a Positional anonymous state variable @.

sub foo($x{
    say (@).push($x);
}
 
foo($_for ^3;
 
# OUTPUT: «[0] 
#          [0 1] 
#          [0 1 2]␤» 

The @ here is parenthesized in order to disambiguate the expression from a class member variable named @.push. Indexed access doesn't require this disambiguation but you will need to copy the value in order to do anything useful with it.

sub foo($x{
    my $v = @;
    $v[$x= $x;
    say $v;
}
 
foo($_for ^3;
 
# OUTPUT: «[0] 
#          [0 1] 
#          [0 1 2]␤» 

As with $, each mention of @ in a scope introduces a new anonymous array.