@@ -76,35 +76,58 @@ routine argument lists.
76
76
= head2 Separating Statements with Semicolons
77
77
78
78
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
+
79
85
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
81
92
82
93
= begin code
83
94
if True {
84
- say "Hello";
95
+ say "Hello"
85
96
}
86
- say "world";
97
+ say "world"
87
98
= end code
88
99
89
- Both semicolons are optional here, but leaving them out increases the chance
90
- of syntax errors when adding more lines later.
91
-
92
100
= head2 Implied Separator Rule (for statements ending in blocks)
93
101
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
95
103
additional statements on the same line follow the block's closing curly
96
104
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
98
112
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 .
101
115
102
116
= begin code
103
117
if True { say "Hello" }; say "world";
104
118
# ^^^ this ; is required
105
119
= end code
106
120
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)
108
131
construct, the implied separator rule only applies at the end of the last block of that series.
109
132
These three are equivalent:
110
133
@@ -125,16 +148,6 @@ else { say "Goodbye" } # <- no semicolon required because it ends in a block
125
148
say "world";
126
149
= end code
127
150
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
-
138
151
= head2 Comments
139
152
140
153
Comments are parts of the program text only intended for human readers, and
0 commit comments