Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
“my” docs mentioning dynamic variables
Explains the relationship between lexical/package and normal/dynamic scope a bit more.

Asked in  #1082
  • Loading branch information
rafaelschipiura committed Sep 3, 2017
1 parent f402b80 commit 56008f7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions doc/Language/variables.pod6
Expand Up @@ -228,7 +228,7 @@ boolean context before using it for anything else:
=begin code
sub foo() {
$*FOO // 'foo';
$*FOO // 'foo';u can send a pull request.
}
say foo; # OUTPUT: «foo␤»
Expand All @@ -238,6 +238,7 @@ boolean context before using it for anything else:
say foo; # OUTPUT: «bar␤»
=end code
Dynamic variables can have lexical scope when declared with C<my> or package scope when declared with C<our>. Dynamic resolution and resolution through symbol tables introduced with C<our> are two orthogonal issues.
=head2 The C<!> Twigil
X<|$!>
Expand Down Expand Up @@ -491,7 +492,7 @@ new-location; # OUTPUT: «outside␤»
=end code
To make C<new-location()> print C<nowhere>, make C<$location> a dynamic
variable using L<the * twigil|#The_*_Twigil>.
variable using L<the * twigil|#The_*_Twigil>. This twigil makes the compiler look up the symbol in the calling scope instead of the outer scope which is the case otherwise.
C<my> is the default scope for subroutines, so C<my sub x() {}> and
C<sub x() {}> do exactly the same thing.
Expand Down

0 comments on commit 56008f7

Please sign in to comment.