Skip to content

Commit cada485

Browse files
committed
Some reflow in preparation for #1603
1 parent 0141d3f commit cada485

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

doc/Language/traps.pod6

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,34 @@ and discovery.
1111
1212
This document aims to show common misconceptions in order to avoid them.
1313
14-
During the making of Perl 6 great pains were taken to get rid of warts in
15-
the syntax. When you whack one wart, though, sometimes another pops up. So
16-
a lot of time was spent finding the minimum number of warts or trying to put
17-
them where they would rarely be seen. Because of this, Perl 6's warts are
18-
in different places than you may expect them to be when coming from another
19-
language.
14+
During the making of Perl 6 great pains were taken to get rid of warts
15+
in the syntax. When you whack one wart, though, sometimes another pops
16+
up. So a lot of time was spent finding the minimum number of warts or
17+
trying to put them where they would rarely be seen. Because of this,
18+
Perl 6's warts are in different places than you may expect them to be
19+
when coming from another language.
2020
2121
=head1 Variables and constants
2222
2323
=head2 Constants are computed at compile time
2424
25-
Constants are computed at compile time, so if you use them in modules keep in mind
26-
that their values will be frozen due to pre-compilation of the module itself:
25+
Constants are computed at compile time, so if you use them in modules
26+
keep in mind that their values will be frozen due to pre-compilation of
27+
the module itself:
2728
2829
=for code :skip-test
2930
# WRONG (most likely):
3031
unit module Something::Or::Other;
3132
constant $config-file = "config.txt".IO.slurp;
3233
33-
The C<$config-file> will be slurped during pre-compilation and changes to
34-
C<config.txt> file won't be re-loaded when you start the script again; only when
35-
the module is re-compiled.
34+
The C<$config-file> will be slurped during pre-compilation and changes
35+
to C<config.txt> file won't be re-loaded when you start the script
36+
again; only when the module is re-compiled.
3637
3738
Avoid L<using a container|/language/containers> and prefer
38-
L<binding a value|/language/containers#Binding> to a variable that offers
39-
a behaviour similar to a constant, but allowing the value to get updated:
39+
L<binding a value|/language/containers#Binding>
40+
to a variable that offers a
41+
behaviour similar to a constant, but allowing the value to get updated:
4042
4143
=for code :skip-test
4244
# Good; file gets updated from 'config.txt' file on each script run:
@@ -45,7 +47,8 @@ my $config-file := "config.txt".IO.slurp;
4547
4648
=head2 Assigning to C<Nil> produces a different value, usually C<Any>.
4749
48-
Actually, assigning to C<Nil> L<reverts the variable to its default value|https://docs.perl6.org/type/Nil>. So:
50+
Actually, assigning to C<Nil>
51+
L<reverts the variable to its default value|https://docs.perl6.org/type/Nil>. So:
4952
5053
=begin code
5154
my @a = 4, 8, 15, 16;
@@ -76,12 +79,14 @@ my $result2 = 'abcdef' ~~ / dex /;
7679
say "Result2 is { $result2.^name }"; # OUTPUT: «Result2 is Any␤»
7780
=end code
7881
79-
A L<C<Match> will be C<Nil>|https://docs.perl6.org/language/regexes#Literals> if it finds nothing; however it assigning C<Nil> to C<$result2> above will result in its default value, which is C<Any> as shown.
82+
A L<C<Match> will be C<Nil>|https://docs.perl6.org/language/regexes#Literals>
83+
if it finds nothing; however it assigning C<Nil> to C<$result2> above
84+
will result in its default value, which is C<Any> as shown.
8085
8186
=head2 Using a block to interpolate anon state vars
8287
83-
The programmer intended for the code to count the number of times the routine
84-
is called, but the counter is not increasing:
88+
The programmer intended for the code to count the number of times the
89+
routine is called, but the counter is not increasing:
8590
8691
=begin code
8792
sub count-it { say "Count is {$++}" }
@@ -94,7 +99,7 @@ is called, but the counter is not increasing:
9499
=end code
95100
96101
When it comes to state variables, the block in which the vars are
97-
declared gets cloned — and vars get initialized anew—whenever that
102+
declared gets cloned —and vars get initialized anew— whenever that
98103
block's block is re-entered. This lets constructs like the one below
99104
behave appropriately: the state variable inside the loop gets
100105
initialized anew each time the sub is called:
@@ -151,8 +156,8 @@ Alternatively, you can also use the L<concatenation operator|/routine/~> instead
151156
152157
=head2 Beware of empty "blocks"
153158
154-
Curly braces are used to declare blocks. However, empty curly braces will
155-
declare a hash.
159+
Curly braces are used to declare blocks. However, empty curly braces
160+
will declare a hash.
156161
157162
=begin code
158163
$ = {say 42;} # Block
@@ -161,7 +166,8 @@ $ = {…} # Block
161166
$ = { } # Hash
162167
=end code
163168
164-
You can use the second form if you effectively want to declare an empty block:
169+
You can use the second form if you effectively want to declare an empty
170+
block:
165171
166172
my &does-nothing = {;};
167173
say does-nothing(33);# OUTPUT: «Nil␤»
@@ -171,9 +177,9 @@ You can use the second form if you effectively want to declare an empty block:
171177
172178
=head2 Assigning to attributes
173179
174-
Newcomers often think that, because attributes with accessors are declared
175-
as C<has $.x>, they can assign to C<$.x> inside the class. That's not the
176-
case.
180+
Newcomers often think that, because attributes with accessors are
181+
declared as C<has $.x>, they can assign to C<$.x> inside the class.
182+
That's not the case.
177183
178184
For example
179185
@@ -229,8 +235,8 @@ class A {
229235
say A.new(x => 42).x; # OUTPUT: «Any␤»
230236
=end code
231237
232-
leaves C<$!x> uninitialized, because the custom C<BUILD> doesn't initialize
233-
it.
238+
leaves C<$!x> uninitialized, because the custom C<BUILD> doesn't
239+
initialize it.
234240
235241
B<Note:> Consider using L<TWEAK|/language/objects#index-entry-TWEAK>
236242
instead. L<Rakudo|/language/glossary#Rakudo> supports L<TWEAK|/language/objects#index-entry-TWEAK> method

0 commit comments

Comments
 (0)