Course of Raku / Essentials / Built-in functions for printing
say
The say
built-in routine does the following actions:
- Calls the
gist
method on its arguments. - Adds a newline character.
- Converts the result to UTF-8.
- Sends it to the
STDOUT
stream.
From the user perspective, say
simply prints the contents of a variable to the terminal and adds the newline.
The first step requires some explanations. The gist
method is a method that is defined for every built-in data type, such as integers or strings. For such simple types, the return result is a human-readable value that represents the item.
say 42; # 42
say 'Raku'; # Raku
For more complex data, such as arrays or hashes, the gist
method adds some formatting.
my @data = 'alpha', 'beta', 'gamma';
say @data; # [alpha beta gamma]
my %data = alpha => 1, beta => 2, gamma => 3;
say %data; # {alpha => 1, beta => 2, gamma => 3}
The say
routine can be called as both a function or a method:
say 42;
say(42);
42.say;
You can pass more than one argument to say
. The output pieces are joint with no spaces between them.
say(100, 500); # 100500
Course navigation
←
Built-in functions for printing
|
Built-in functions for printing / print
→
💪 Or jump directly to the exercises to this section.
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська