routine dynamic

Documentation for routine dynamic assembled from the following types:

class Scalar

From Scalar

(Scalar) method dynamic

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

Returns whether the variable is visible in dynamic variable lookups.

Example:

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

class Array

From Array

(Array) routine dynamic

Defined as:

method dynamic(Array:D: --> 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 = [123];
say $s.dynamic;                          # OUTPUT: «False␤»  (wrong, don't do this) 
say $s.VAR.dynamic;                      # OUTPUT: «True␤»   (correct approach)

class Hash

From Hash

(Hash) routine dynamic

Defined as:

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)