Course of Raku / Advanced / More about built-in types / Native types 🆕 / Exercises / The native default
Solution: The native default
Here is a possible solution to the task.
Code
my num $n;
my str $s;
say $n;
say "[$s]";🦋 You can find the source code in the file native-default.raku.
Output
0
[]Comments
A native
numcannot be undefined, so like a nativeintit starts at0rather than at(Num).A native
strstarts as the empty string, which is why the brackets come out with nothing between them. None of the native types ever hold an undefined value.The type specifiers are essential here. Drop them — write
my $n; my $s;— and the variables become ordinary containers that start out undefined (Any). Thensay $nprints(Any), and interpolating the undefined$swarns “Use of uninitialized value … in string context”. It is the nativenumandstrtypes that guarantee the0and empty-string defaults.