How to resolve the algorithm Undefined values step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Undefined values step by step in the Raku programming language

Table of Contents

Problem Statement

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Undefined values step by step in the Raku programming language

Source code in the raku programming language

my $x; $x = 42; $x = Nil; say $x.WHAT; # prints Any()


say Method ~~ Routine;  # Bool::True


my     $x; say $x.WHAT; # Any()
my Int $y; say $y.WHAT; # Int()
my Str $z; say $z.WHAT; # Str()


my Int:D $i = 1; # if $i has to be defined you must provide a default value
multi sub foo(Int:D $i where * != 0){ (0..100).roll / $i } # we will never divide by 0
multi sub foo(Int:U $i){ die 'WELP! $i is undefined' } # because undefinedness is deadly

with $i { say 'defined' } # as "if" is looking for Bool::True, "with" is looking for *.defined
with 0 { say '0 may not divide but it is defined' }


my $is-defined = 1;
my $ain't-defined = Any;
my $doesn't-matter;
my Any:D $will-be-defined = $ain't-defined // $is-defined // $doesn't-matter;

my @a-mixed-list = Any, 1, Any, 'a';
$will-be-defined = [//] @a-mixed-list; # [//] will return the first defined value

my @a = Any,Any,1,1;
my @b = 2,Any,Any,2;
my @may-contain-any = @a >>//<< @b; # contains: [2, Any, 1, 1]

sub f1(){Failure.new('WELP!')};
sub f2(){ $_ ~~ Failure }; # orelse will kindly set the topic for us
my $s = (f1() orelse f2()); # Please note the parentheses, which are needed because orelse is
                            # much looser then infix:<=> .
dd $s; # this be Bool::False


  

You may also check:How to resolve the algorithm Hello world/Text step by step in the RASEL programming language
You may also check:How to resolve the algorithm Plot coordinate pairs step by step in the REXX programming language
You may also check:How to resolve the algorithm Curzon numbers step by step in the Perl programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the Go programming language
You may also check:How to resolve the algorithm Null object step by step in the PicoLisp programming language