Skip to content

Commit 2854b7d

Browse files
moleculeszoffixznet
authored andcommitted
Cleaning up "Separating statements by semicolons" (#1479)
* Cleaning up "Separating statements by semicolons" Trying to address #1477 * More explanation, postcircumfix exception * More concise trailing statement explanation * removed mention of postcircumfix blocks Deleting to avoid confusion
1 parent f75c499 commit 2854b7d

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

doc/Language/syntax.pod6

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,35 +76,58 @@ routine argument lists.
7676
=head2 Separating Statements with Semicolons
7777
7878
A Perl 6 program is a list of statements, separated by semicolons C<;>.
79+
80+
=begin code
81+
say "Hello";
82+
say "world";
83+
=end code
84+
7985
A semicolon after the final statement (or after the final statement inside a
80-
block) is optional, though it's good form to include it.
86+
block) is optional.
87+
88+
=begin code
89+
say "Hello";
90+
say "world"
91+
=end code
8192
8293
=begin code
8394
if True {
84-
say "Hello";
95+
say "Hello"
8596
}
86-
say "world";
97+
say "world"
8798
=end code
8899
89-
Both semicolons are optional here, but leaving them out increases the chance
90-
of syntax errors when adding more lines later.
91-
92100
=head2 Implied Separator Rule (for statements ending in blocks)
93101
94-
Complete statements ending in blocks can omit the trailing semicolon, if no
102+
Complete statements ending in bare blocks can omit the trailing semicolon, if no
95103
additional statements on the same line follow the block's closing curly
96104
brace C<}>. This is called the "implied separator rule". For example, you
97-
don't need to write a semicolon after an C<if> statement block as seen above.
105+
don't need to write a semicolon after an C<if> statement block as seen above, and
106+
below.
107+
108+
=begin code
109+
if True { say "Hello" }
110+
say "world";
111+
=end code
98112
99-
If you want additional statements to trail the block, you do need to include
100-
a semicolon between the block and the statement.
113+
However, semicolons are required to separate a block from trailing statements in
114+
the same line.
101115
102116
=begin code
103117
if True { say "Hello" }; say "world";
104118
# ^^^ this ; is required
105119
=end code
106120
107-
However, for a series of blocks that are part of the same C<if>/C<elsif>/C<else> (or similar)
121+
This implied statement separator rule applies in other ways, besides control
122+
statements, that could end with a bare block. For example, in combination with
123+
the colon C<:> syntax for method calls.
124+
125+
=begin code
126+
my @names = <Foo Bar Baz>;
127+
my @upper-case-names = @names.map: { .uc } # OUTPUT: [FOO BAR BAZ]
128+
=end code
129+
130+
For a series of blocks that are part of the same C<if>/C<elsif>/C<else> (or similar)
108131
construct, the implied separator rule only applies at the end of the last block of that series.
109132
These three are equivalent:
110133
@@ -125,16 +148,6 @@ else { say "Goodbye" } # <- no semicolon required because it ends in a block
125148
say "world";
126149
=end code
127150
128-
But, remember, this implied statement separator rule applies in other ways that
129-
statements could end with block. For example, in combination with the colon C<:>
130-
syntax for method calls:
131-
132-
=begin code
133-
my @names = <Foo Bar Baz>;
134-
my @upper-case-names = @names.map: { .uc }
135-
# [FOO BAR BAZ]
136-
=end code
137-
138151
=head2 Comments
139152
140153
Comments are parts of the program text only intended for human readers, and

0 commit comments

Comments
 (0)