@@ -80,11 +80,11 @@ method is automatically generated.
80
80
Thus the correct way to write method C < double > is
81
81
82
82
= for code :skip-test
83
- method double {
84
- $!x *= 2;
85
- $!y *= 2;
86
- self;
87
- }
83
+ method double {
84
+ $!x *= 2;
85
+ $!y *= 2;
86
+ self;
87
+ }
88
88
89
89
which operates on the attributes directly.
90
90
@@ -116,17 +116,17 @@ since release 2016.11.
116
116
One possible remedy is to explicitly initialize the attribute in C < BUILD > :
117
117
118
118
= for code :skip-test
119
- submethod BUILD(:$x) {
120
- $!y = 18;
121
- $!x := $x;
122
- }
119
+ submethod BUILD(:$x) {
120
+ $!y = 18;
121
+ $!x := $x;
122
+ }
123
123
124
124
which can be shortened to:
125
125
126
126
= for code :skip-test
127
- submethod BUILD(:$!x) {
128
- $!y = 18;
129
- }
127
+ submethod BUILD(:$!x) {
128
+ $!y = 18;
129
+ }
130
130
131
131
Another, more general approach is to leave C < BUILD > alone, and hook into the
132
132
C < BUILDALL > mechanism instead:
@@ -596,11 +596,11 @@ say %h.perl
596
596
Sometimes you may need to match a generated string in a regex. The
597
597
right way to do it is to use C < $(…) > or C « <{…}> » syntax.
598
598
599
- = for code
600
- my $x = ‘ailemac’;
601
- say ‘I ♥ camelia’ ~~ / $($x.flip) /; # OUTPUT: «「camelia」»
602
- my $x = ‘ailemac’;
603
- say ‘I ♥ camelia’ ~~ / <{$x.flip}> /; # OUTPUT: «「camelia」»
599
+ = for code
600
+ my $x = ‘ailemac’;
601
+ say ‘I ♥ camelia’ ~~ / $($x.flip) /; # OUTPUT: «「camelia」»
602
+ my $x = ‘ailemac’;
603
+ say ‘I ♥ camelia’ ~~ / <{$x.flip}> /; # OUTPUT: «「camelia」»
604
604
605
605
However, there is a wrong way to write it, and the problem is that
606
606
it works I < sometimes > .
@@ -609,21 +609,21 @@ Internally C«<{…}>» EVAL-s the given string inside an anonymous regex, while
609
609
C < $(…) > lexically interpolates the given string. So C « <{…}> » immediately breaks
610
610
with more complicated inputs. For example:
611
611
612
- = for code :skip-test
613
- my $x = ‘ailemac#’;
614
- say ‘I ♥ #camelia’ ~~ / $($x.flip) /; # OUTPUT: «「#camelia」»
615
- # ⚠ ↓↓ WRONG ↓↓ ⚠
616
- say ‘I ♥ camelia’ ~~ / <{$x.flip}> /; # OUTPUT: «「camelia」»
617
- # OUTPUT:
618
- # ===SORRY!===
619
- # Regex not terminated.
620
- # at EVAL_0:1
621
- # ------> anon regex { #camelia}⏏<EOL>
622
- # Malformed regex
623
- # at EVAL_0:1
624
- # ------> anon regex { #camelia}⏏<EOL>
625
- # expecting any of:
626
- # infix stopper
612
+ = for code :skip-test
613
+ my $x = ‘ailemac#’;
614
+ say ‘I ♥ #camelia’ ~~ / $($x.flip) /; # OUTPUT: «「#camelia」»
615
+ # ⚠ ↓↓ WRONG ↓↓ ⚠
616
+ say ‘I ♥ camelia’ ~~ / <{$x.flip}> /; # OUTPUT: «「camelia」»
617
+ # OUTPUT:
618
+ # ===SORRY!===
619
+ # Regex not terminated.
620
+ # at EVAL_0:1
621
+ # ------> anon regex { #camelia}⏏<EOL>
622
+ # Malformed regex
623
+ # at EVAL_0:1
624
+ # ------> anon regex { #camelia}⏏<EOL>
625
+ # expecting any of:
626
+ # infix stopper
627
627
628
628
Therefore, try not to use C « <{}> » unless you really need EVAL.
629
629
@@ -1007,9 +1007,9 @@ can await on. The solution is even more beautiful if you are
1007
1007
working in a L < react|/language/concurrency#index-entry-react > block:
1008
1008
1009
1009
= begin code :skip-test
1010
- whenever $proc.print: “one\ntwo\nthree\nfour” {
1011
- $proc.close-stdin;
1012
- }
1010
+ whenever $proc.print: “one\ntwo\nthree\nfour” {
1011
+ $proc.close-stdin;
1012
+ }
1013
1013
= end code
1014
1014
1015
1015
= head2 Using <.stdout> without <.lines>
@@ -1259,7 +1259,7 @@ The right way to do it is to I<always> check that whatever you use in
1259
1259
your C < LEAVE > block is defined:
1260
1260
1261
1261
= begin code :skip-test
1262
- LEAVE say .Int with $x
1262
+ LEAVE say .Int with $x
1263
1263
= end code
1264
1264
1265
1265
= head1 Unfortunate generalization
0 commit comments