Skip to content

Commit fbaf86a

Browse files
committed
Document the failure nature of undeclared dynvars
1 parent fa86569 commit fbaf86a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

doc/Language/variables.pod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ C<$*dynamic2> is still C<101>. This stems from the fact that we declared a
193193
new dynamic variable C<$*dynamic1> in the block and did not assign to the
194194
old variable as we did with C<$*dynamic2>.
195195
196+
The dynamic variables differ from other variable types in that refering
197+
to an undeclared dynamic variable is not a compile time error but a
198+
runtime L<failure|/type/Failure>, so a dynamic variable variable can be
199+
used undeclared as long as it is checked for definedness or used in a
200+
boolean context before using it for anything else:
201+
202+
=begin code
203+
sub foo() {
204+
$*FOO // 'foo';
205+
}
206+
207+
say foo; # -> 'foo'
208+
209+
my $*FOO = 'bar';
210+
211+
say foo; # -> 'bar'
212+
=end code
213+
214+
196215
=head2 The C<!> Twigil
197216
198217
Attributes are variables that exist per instance of a class. They may be

0 commit comments

Comments
 (0)