πŸ“˜ Bool in Perl 6

The usage of the Bool variables is straightforward although there are some details about which you might want to know. The Bool type is a built-in enumeration and provides two values: True and False (or, in a full form, Bool::True and Bool::False). It is permissible to increment or decrement the Boolean variables:

my $b = Bool::True;
$b--;
say $b; # prints False

$b = Bool::False;
$b++;
say $b; # True

The Perl 6 objects (namely, all variables) contain the Bool method, which converts the value of the variable to one of the two Boolean values:

say 42.Bool; # True

my $pi = 3.14;
say $pi.Bool; # True

say 0.Bool;Β Β  Β # False
say "00".Bool; # True

Similarly, you may call the Int method on a variable and get the integer representation of the Boolean values (or values of any other types):

say Bool::True.Int; # 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s