is default (Variable) trait is default
1 | class Variable |
1.1 | (Variable) is default (Variable) trait is default |
Documentation for is default (Variable) trait is default
assembled from the following types:
class Variable
From Variable
(Variable) is default (Variable) trait is default
Sets the default value with which a variable is initialized, and to which it is reset when Nil is assigned to it. Trait arguments are evaluated at compile time. Closures won't do what you expect: they are stored as is and need to be called by hand.
my Int is default(42);say ; # OUTPUT: «42»= 5;say ; # OUTPUT: «5»# explicit reset:= Nil;say ; # OUTPUT: «42»
The trait is default
can be used also with subscripting things like arrays and hashes:
my is default( 'N/A' );[22].say; # OUTPUT: N/A= Nil;.say; # OUTPUT: [N/A][4].say; # OUTPUT: N/Amy is default( 'no-value-here' );<non-existent-key>.say; # OUTPUT: no-value-here<foo> = 'bar';<>.say; # OUTPUT: {foo => bar}<wrong-key>.say; # OUTPUT: no-value-here