Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Creates a new file for statement prefixes.
This is for #534, but mainly for #2034
Still way to go.
  • Loading branch information
JJ committed Apr 15, 2019
1 parent 4d91061 commit d166589
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/Language/00-POD6-CONTROL
Expand Up @@ -80,6 +80,7 @@ Quoting constructs FILE: quoting
Regexes FILE: regexes
Routines FILE: routines
Sets, bags, and mixes FILE: setbagmix
Statement prefixes FILE: statement-prefixes
Subscripts FILE: subscripts
Syntax FILE: syntax
System interaction FILE: system
Expand Down
39 changes: 39 additions & 0 deletions doc/Language/statement-prefixes.pod6
@@ -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

0 comments on commit d166589

Please sign in to comment.