File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -277,9 +277,36 @@ sub postfix:<!>(Int $x where { $x >= 0 }) { [*] 1..$x };
277
277
say 6!; # 720
278
278
= end code
279
279
280
- = begin comment
281
- TODO: elaborate on (post)circumfix ops
282
- = end comment
280
+ The operator declaration becomes available as soon as possible, so you can
281
+ even recurse into a just-defined operator, if you really want to:
282
+
283
+ = begin code
284
+ sub postfix:<!>(Int $x where { $x >= 0 }) {
285
+ $x == 0 ?? 1 !! $x * ($x - 1)!
286
+ }
287
+ say 6!; # 720
288
+ = end code
289
+
290
+ Circumfix and postcircumfix operators are made of two delimiters, one opening
291
+ and one closing.
292
+
293
+ = begin code
294
+ sub circumfix:<START END>(*@elems) {
295
+ "start", @elems, "end"
296
+ }
297
+
298
+ say START 'a', 'b', 'c' END; # start a b c end
299
+ = end code ;
300
+
301
+ Postcircumfixes also receive the the term after which they are parsed as
302
+ an argument:
303
+
304
+ = begin code
305
+ sub postcircumfix:<!! !!>($left, $inside) {
306
+ "$left -> ( $inside )"
307
+ }
308
+ say 42!! 1 !!; # 42 -> ( 1 )
309
+ = end code
283
310
284
311
= head2 Precedence
285
312
You can’t perform that action at this time.
0 commit comments