Skip to content

Commit

Permalink
Rearranges the description of dynamic for Scalar and Array.
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Jun 19, 2020
1 parent 0980a9c commit 023c7de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 6 additions & 8 deletions doc/Type/Array.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,15 @@ returns C<(Mu)>.
CATCH { default { put .^name, ': ', .Str } };
# OUTPUT: «X::TypeCheck::Assignment: Type check failed in assignment to @a2; expected Int but got Str ("d")␤»
=head2 routine dynamic
=head2 method dynamic
Defined as:
method dynamic(Array:D: --> Bool:D)
Returns C<True> if the invocant has been declared with the L<is dynamic|/routine/is dynamic>
trait.
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␤»
Expand All @@ -365,12 +366,9 @@ If you declare a variable with the C<*> twigil C<is dynamic> is implied.
my @*b;
say @*b.dynamic; # OUTPUT: «True␤»
Note that in the L<Scalar|/type/Scalar> case you have to use the C<VAR> method in
order to get correct information.
my $s is dynamic = [1, 2, 3];
say $s.dynamic; # OUTPUT: «False␤» (wrong, don't do this)
say $s.VAR.dynamic; # OUTPUT: «True␤» (correct approach)
Please note that the C<dynamic> trait is a property of the variable, not the
content. If a C<Scalar> dynamic variable contains an array, rules for this
container will apply (and it will always return C<False>).
=end pod

Expand Down
8 changes: 7 additions & 1 deletion doc/Type/Scalar.pod6
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,19 @@ Example:
method dynamic(Scalar:D: --> Bool)
Returns whether the variable is visible in dynamic variable lookups.
It will return C<False> for scalars.
Example:
my $*FOO = 42;
say $*FOO.VAR.dynamic; # OUTPUT: «True»
Note that you have to use the C<VAR> method in order to get that information.
my $s is dynamic = [1, 2, 3];
say $s.dynamic; # OUTPUT: «False␤» (wrong, don't do this)
say $s.VAR.dynamic; # OUTPUT: «True␤» (correct approach)
=head1 Routines
=head2 sub atomic-assign
Expand Down

0 comments on commit 023c7de

Please sign in to comment.