Undefined values: Difference between revisions
m
→{{header|Raku}}: Fix links and comments: Perl 6 --> Raku
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: Fix links and comments: Perl 6 --> Raku) |
||
Line 1,212:
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>my $x; $x = 42; $x = Nil; say $x.WHAT; # prints Any()</lang>
This <tt>Any</tt> is an example of another kind of undefined type, which is a typed undef. All reference types have an undefined value representing the type. You can think of it as a sort of "type gluon" that carries a type charge without being a "real" particle. Hence there are undefined values whose names represent types, such as <tt>Int</tt>, <tt>Num</tt>, <tt>Str</tt>, and all the other object types in
<lang perl6>say Method ~~ Routine; # Bool::True</lang>
Line 1,225:
my Str $z; say $z.WHAT; # Str()</lang>
The user-interface for definedness are [http://design.
<lang perl6>my Int:D $i = 1; # if $i has to be defined you must provide a default value
Line 1,235:
</lang>
There are further some [http://design.
<lang perl6>my $is-defined = 1;
Line 1,255:
dd $s; # this be Bool::False</lang>
Finally, another major group of undefined values represents failures.
Native storage types work under different rules, since most native types cannot represent failure, or even undefinedness. Any attempt to assign a value to a storage location that cannot represent a failure will cause an exception to be thrown.
|