Skip to content

Commit fca9214

Browse files
authored
make examples for is dynamic look parallel (#4687)
* make examples for `is dynamic` look parallel In particular, put both inside a block. * rearrange example with twigil `$*x` accordingly * add link to /language/variables#The_*_twigil * add ling to /type/Variable#trait_is_dynamic * clarify that this section is only about *pre-defined* dynamic variables
1 parent 0812f14 commit fca9214

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

doc/Language/variables.rakudoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,12 @@ my $*FOO = 'bar';
300300
say foo; # OUTPUT: «bar␤»
301301
=end code
302302

303+
See also L<trait is dynamic|/type/Variable#trait_is_dynamic>.
304+
303305
Dynamic variables can have lexical scope when declared with C<my> or package
304306
scope when declared with C<our>. Dynamic resolution and resolution through
305307
symbol tables introduced with C<our> are two orthogonal issues.
306308

307-
308309
X<|Syntax,$?>X<|Syntax,?>X<|Syntax,$?>X<|Syntax,@?>X<|Syntax,%?>X<|Syntax,&?>
309310
=head2 The C<?> twigil
310311

@@ -1524,8 +1525,8 @@ sub get-file-content {
15241525

15251526
=head2 Dynamic variables
15261527

1527-
All dynamically scoped variables have the C<*> twigil, and their name is
1528-
(conventionally) written in uppercase.
1528+
The pre-defined dynamically scoped variables all have the L<C<*> twigil|#The_*_twigil>,
1529+
and their name is (conventionally) written in uppercase.
15291530

15301531
X<|Variables,$*ARGFILES>X<|Variables,@*ARGS>
15311532
=head3 Argument related variables
@@ -1866,7 +1867,7 @@ To activate this only for a lexical scope:
18661867
my $*RAT-OVERFLOW = FatRat;
18671868
=end code
18681869

1869-
How does that work? The $*RAT-OVERFLOW variable is supposed to contain
1870+
How does that work? The C<$*RAT-OVERFLOW> variable is supposed to contain
18701871
a class or instance on which the C<UPGRADE-RAT> method will be called
18711872
when a Rat overflows. So you can introduce your own behavior by
18721873
creating a class with an C<UPGRADE-RAT> method in it.

doc/Type/Variable.rakudoc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,30 @@ without being in an inner lexical scope.
6060
sub introspect() {
6161
say $CALLER::x;
6262
}
63-
my $x is dynamic = 23;
64-
introspect; # OUTPUT: «23␤»
6563
{
66-
# not dynamic
67-
my $x;
68-
introspect() # dies with an exception of X::Caller::NotDynamic
64+
my $x is dynamic = 42;
65+
introspect(); # OUTPUT: «42␤»
66+
}
67+
{
68+
my $x = 41; # not dynamic
69+
introspect(); # dies with an exception of X::Caller::NotDynamic
6970
}
7071
=end code
7172

7273
The C<is dynamic> trait is a rather cumbersome way of creating and accessing
73-
dynamic variables. A much easier way is to use the C<* twigil>:
74+
dynamic variables. A much easier way is to use the L<C<* twigil>|/language/variables#The_*_twigil>:
7475

7576
=begin code
7677
sub introspect() {
7778
say $*x;
7879
}
79-
my $*x = 23;
80-
introspect; # OUTPUT: «23␤»
8180
{
82-
# not dynamic
83-
my $x;
84-
introspect() # dies with an exception of X::Dynamic::NotFound
81+
my $*x = 42;
82+
introspect(); # OUTPUT: «42␤»
83+
}
84+
{
85+
my $x = 41; # not dynamic
86+
introspect(); # dies with an exception of X::Dynamic::NotFound
8587
}
8688
=end code
8789

0 commit comments

Comments
 (0)