dynamic
ErrorsCollection

dynamic

Synthesised documentation from type/Array type/Scalar type/Hash

From type/Array

See Original text in context

method dynamic(Array:D: --> Bool:D)

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 @a;
say @a.dynamic;                          # OUTPUT: «False␤» 
 
my @b is dynamic;
say @b.dynamic;                          # OUTPUT: «True␤»

If you declare a variable with the * twigil is dynamic is implied.

my @*b;
say @*b.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).

From type/Scalar

See Original text in context

method dynamic(Scalar:D: --> Bool)

It will return False for scalars.

Example:

my $*FOO = 42;
say $*FOO.VAR.dynamic;          # OUTPUT: «True»

Note that you have to use the VAR method in order to get that information.

my $s is dynamic = [123];
say $s.dynamic;                          # OUTPUT: «False␤»  (wrong, don't do this) 
say $s.VAR.dynamic;                      # OUTPUT: «True␤»   (correct approach)

From type/Hash

See Original text in context

method dynamic(--> Bool:D)

Returns True if the invocant has been declared with the is dynamic trait.

my %a;
say %a.dynamic;                          # OUTPUT: «False␤» 
 
my %b is dynamic;
say %b.dynamic;                          # OUTPUT: «True␤»

If you declare a variable with the * twigil is dynamic is implied.

my %*b;
say %*b.dynamic;                         # OUTPUT: «True␤»

Note that in the Scalar case you have to use the VAR method in order to get correct information.

my $s is dynamic = %('apples' => 5);
say $s.dynamic;                   # OUTPUT: «False␤»  (wrong, don't do this) 
say $s.VAR.dynamic;               # OUTPUT: «True␤»   (correct approach)