See Original text in context
method default(Baggy: --> 0)
Returns zero.
my = bag <eggs bacon>;say .default; # OUTPUT: «0»
See Original text in context
method default
Returns the default value of the invocant, i.e. the value which is returned when trying to access an element in the Array
which has not been previously initialized or when accessing an element which has explicitly been set to Nil
. Unless the Array
is declared as having a default value by using the is default trait the method returns the type object (Any)
.
my = 1, "two", 2.718;say .default; # OUTPUT: «(Any)»say [4]; # OUTPUT: «(Any)»my is default(17) = 1, "two", 3;say .default; # OUTPUT: «17»say [4]; # OUTPUT: «17»[1] = Nil; # (resets element to its default)say [1]; # OUTPUT: «17»
See Original text in context
method default(Scalar: --> Str)
Returns the default value associated with the container.
Example:
my is default(666) = 42;say .VAR.default; # OUTPUT: «666»
See Original text in context
method default(--> False)
Returns the default value of the invocant, i.e. the value which is returned when trying to access an element in the Setty
object which has not been previously initialized or when accessing an element which has explicitly been set to Nil
or False
.
my = SetHash.new(1, 2, 3);say ; # OUTPUT: «True»= Nil;say ; # OUTPUT: «False»# access non initialized elementsay ; # OUTPUT: «False»
See Original text in context
method default(Hash:)
Returns the default value of the invocant, i.e. the value which is returned when a non existing key is used to access an element in the Hash
. Unless the Hash
is declared as having a default value by using the is default trait the method returns the type object (Any)
.
my = 'apples' => 3, 'oranges' => 7;say .default; # OUTPUT: «(Any)»say ; # OUTPUT: «(Any)»my is default(1) = 'apples' => 3, 'oranges' => 7;say .default; # OUTPUT: «1»say + ; # OUTPUT: «4»
See Original text in context
method default(Parameter: --> Code)
Returns a closure that upon invocation returns the optional parameters for this parameter, or Code
if no default was provided.
Note: Before Rakudo version 2020.08 the return value for a parameter with no default value was Any
.
my = :(, = 12);say .params[0].default; # OUTPUT: «(Code)»say .params[1].default.(); # OUTPUT: «12»