Course of Raku / Essentials / Positional data types

Quoting string arrays

For string arrays, where the items are short strings with no spaces, Raku offers a nice syntax for initialising them.

my @digits = <zero one two three four five six seven eight nine>;

It is up to you to decide to add additional spaces around the angle brackets or not. The compiler accepts both options.

my @digits = < zero one two three four five six seven eight nine >;

Both constructions are equivalent to a straightforward variant:

my @digits = 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine';

Array vs List

Notice that in the examples above, the quotation < . . . > creates a List, not an Array. You can confirm it by calling the WHAT method:

say <a b c>.WHAT; # (List)

Nevertheless, when you assign it to an array, you get an array with the elements from the list.

my @a = <a b c>;
say @a.WHAT; # (Array)

Practice

Complete the quizzes that cover the contents of this topic.

Course navigation

Positional data types / Lists   |   Positional data types / Subscripting ranges


💪 Or jump directly to the exercises to this section.