Documentation for routine dynamic
assembled from the following pages:
Class: Hash §
From Hash
(Hash) routine dynamic §
Defined as:
method dynamic(--> Bool)
Returns True
if the invocant has been declared with the is dynamic trait.
my ;say .dynamic; # OUTPUT: «False» my is dynamic;say .dynamic; # OUTPUT: «True»
If you declare a variable with the *
twigil is dynamic
is implied.
my ;say .dynamic; # OUTPUT: «True»
Note that in the Scalar case you have to use the VAR
method in order to get correct information.
my is dynamic = %('apples' => 5);say .dynamic; # OUTPUT: «False» (wrong, don't do this) say .VAR.dynamic; # OUTPUT: «True» (correct approach)
Class: Scalar §
From Scalar
(Scalar) method dynamic §
method dynamic(Scalar: --> Bool)
It will return False
for scalars.
Example:
my = 42;say .VAR.dynamic; # OUTPUT: «True»
Note that you have to use the VAR
method in order to get that information.
my is dynamic = [1, 2, 3];say .dynamic; # OUTPUT: «False» (wrong, don't do this) say .VAR.dynamic; # OUTPUT: «True» (correct approach)
Class: Array §
From Array
(Array) method dynamic §
Defined as:
method dynamic(Array: --> Bool)
Returns True
if the invocant has been declared with the is dynamic trait, that is, if it's a dynamic variable that can be accessed from the inner lexical scope without having been declared there.
my ;say .dynamic; # OUTPUT: «False» my is dynamic;say .dynamic; # OUTPUT: «True»
If you declare a variable with the *
twigil is dynamic
is implied.
my ;say .dynamic; # OUTPUT: «True»
Please note that the dynamic
trait is a property of the variable, not the content. If a Scalar
dynamic variable contains an array, rules for this container will apply (and it will always return False
).