Types, classes & roles
Definedness & type objects
FullEvery type has an undefined "type object"; .defined tells values and types apart.
Definedness is distinct from truth. Every type has a type object — an undefined instance of the type (Int, Any, …) — and .defined distinguishes it from a real value. This is what with/without and optional parameters key on.
Values are defined, type objects are not #
my $x; say $x.defined; say 0.defined; say Any.defined;
Output
False
True
FalseAn uninitialised $x holds Any (undefined); 0 is a defined value even though it is false; a bare type name is the undefined type object.
Nil and type objects #
say Nil.defined; say (Int).defined; say 42.defined;
Output
False
False
TrueInt (the type object) is undefined; 42 (an instance) is defined.
Notes #
- Definedness ≠ truth:
0and""are defined but false, which is exactly why//(defined-or) andwithdiffer from||andif— see Logical operators. - A parameter typed
Int:Drequires a defined Int;Int:Urequires the undefined type object — the:D/:U"definedness smileys". - Type objects are how Raku represents "no value of this type yet", replacing null with something type-aware.