Course of Raku / Essentials / Typed variables / Exercises / Create variables of all known types

Solution: Create variables of all known types

Probably, this is not a kind of programs that you will create in your practice. Nevertheless, it is important to know how to introspect the parts of real programs.

Code

Here is a possible solution that creates the variables of the four mentioned types and prints their types.

my $a = 10;
my $b = 10.2;
my $c = 10e3;
my $d = True;
my $e = 'ten';

say $a, ' ', $a.WHAT;
say $b, ' ', $b.WHAT;
say $c, ' ', $c.WHAT;
say $d, ' ', $d.WHAT;
say $e, ' ', $e.WHAT;

🦋 Find the program in the file types.raku.

Output

This program prints the following output:

$ raku exercises/data-types/types.raku
10 (Int)
10.2 (Rat)
10000 (Num)
True (Bool)
ten (Str)

Course navigation

Data type conversion / Converting types with prefix operators   |   Positional data types