In Array§
See primary documentation in context for method dynamic
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
).
In Scalar§
See primary documentation in context for 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)
In Hash§
See primary documentation in context for routine dynamic
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)