Course of Raku / Essentials / More about types / 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 whether 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';%%tipblock ## 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
← Quiz — List and scalar vs. list and array | Quiz 1 — Quoting string arrays →
💪 Or jump directly to the exercises in this
section.
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська