Skip to content

Commit 144a3a9

Browse files
committed
show difference between implicit and explicit state delcarator
1 parent 7685316 commit 144a3a9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

doc/Language/variables.pod6

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,14 @@ scope it should be copied to a new variable.
691691
foo() for ^3;
692692
# OUTPUT«one␤two␤three␤»
693693
694+
Please note that the implicit state declarator is only applied to the variable
695+
itself, not the expression that may contain an initializator. If the
696+
initializer has to be called exactly once, the C<state> declarator has to be
697+
provided.
698+
699+
subset DynInt where $ = ::('Int'); # the initializer will be called for each type check
700+
subset DynInt where state $ = ::('Int'); # the initializer is called once, this is a proper cache
701+
694702
=head3 The C<@> Variable
695703
696704
In a similar manner to the C<$> variable there is also a L<Positional>

0 commit comments

Comments
 (0)