Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Creates a new file for statement prefixes.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| =begin pod :tag<perl6> | ||
| =TITLE Statement prefixes | ||
| =SUBTITLE Prefixes that alter the behavior of a statement of set of them | ||
| Statement prefixes are not statements per se. They are written in front of a | ||
| statement, and change their meaning, their output, or the moment they are going | ||
| to be run. Since they have a specific behavior, they are also sometimes specific | ||
| to some statement or statements. | ||
| =head2 X<C<lazy>|lazy (statement prefix)> | ||
| As a statement prefix, lazy acts on C<for> loops, saving the execution for when | ||
| the variable they are assigned for is actually needed. | ||
| =for code | ||
| my $incremented = 0; | ||
| my $var = lazy for <1 2 3 4> -> $d { | ||
| $incremented++ | ||
| }; | ||
| say $incremented; # OUTPUT: «0» | ||
| say eager $var; # OUTPUT: «(0 1 2 3)» | ||
| say $incremented; # OUTPUT: «4» | ||
| The C<$incremented> variable is only incremented, that is, the internal part of | ||
| the loop is only run, when we eagerly evaluate the variable C<$var> that | ||
| contains the lazy loop. Eagerness can be applied on a variable in other ways, | ||
| such as calling the C<.eager> method on it. | ||
| This prefix can also be used | ||
| L<in front of C<gather>|/language/control#gather/take> to make the inner | ||
| statements behave lazily. | ||
| =end pod | ||
|
|
||
| # vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 |