@@ -344,33 +344,34 @@ many modules, will follow.
344
344
345
345
= head2 Slurpy Conventions
346
346
347
- Perhaps the most important of these is the way slurpy list arguments are
347
+ Perhaps the most important one of these conventions is the way slurpy list arguments are
348
348
handled. Most of the time, functions will not automatically flatten
349
- slurpy lists. The rare exceptions are those functions that don't have a
350
- reasonable behavior on lists of lists; for example, L < chrs|/routine/chrs > ,
351
- or where there is a conflict with an established idiom, like L < pop|/routine/pop >
352
- being the inverse of L < push|/routine/push > .
349
+ slurpy lists.
350
+ The rare exceptions are those functions that don't have a
351
+ reasonable behavior on lists of lists (e.g., L < chrs|/routine/chrs > )
352
+ or where there is a conflict with an established idiom (e.g., L < pop|/routine/pop >
353
+ being the inverse of L < push|/routine/push > ).
353
354
354
- If you wish to match this look and feel, any Iterable argument must
355
- be broken out element-by-element using a **@ slurpy, with two nuances:
355
+ If you wish to match this look and feel, any L < Iterable|/type/Iterable > argument must
356
+ be broken out element-by-element using a C < **@ > slurpy, with two nuances:
356
357
357
- = item An Iterable inside a L < Scalar container|/language/containers#Scalar_containers > doesn't count.
358
+ = item An L < Iterable|/type/Iterable > inside a L < Scalar container|/language/containers#Scalar_containers > doesn't count.
358
359
359
- = item Lists created with a L < C < , > |/routine/,> at the top level only count as one Iterable.
360
+ = item L < List|/type/List > s created with a L < C < , > |/routine/,> at the top level only count as one L < Iterable|/type/Iterable > .
360
361
361
362
This can be achieved by using a slurpy with a C < + > or C < +@ > instead of C < ** > :
362
363
363
364
sub grab(+@a) { "grab $_".say for @a }
364
365
365
- ... which is shorthand for something very close to:
366
+ which is shorthand for something very close to:
366
367
367
368
multi sub grab(**@a) { "grab $_".say for @a }
368
369
multi sub grab(\a) {
369
370
a ~~ Iterable and a.VAR !~~ Scalar ?? nextwith(|a) !! nextwith(a,)
370
371
}
371
372
372
- This results in the following behavior, which is known as the "single
373
- argument rule" and is important to understand when invoking slurpy functions:
373
+ This results in the following behavior, which is known as the
374
+ I < "single argument rule"> and is important to understand when invoking slurpy functions:
374
375
375
376
= for code :preamble<sub grab(+@a) {};>
376
377
grab(1, 2); # OUTPUT: «grab 1grab 2»
@@ -388,7 +389,7 @@ grab(flat (1, 2)); # OUTPUT: «grab 1grab 2»
388
389
grab(flat $(1, 2)); # OUTPUT: «grab 1grab 2»
389
390
390
391
It's worth noting that mixing binding and sigilless variables
391
- in these cases requires a bit of finesse, because there is no Scalar
392
+ in these cases requires a bit of finesse, because there is no L < Scalar|/type/Scalar >
392
393
intermediary used during binding.
393
394
394
395
= for code :preamble<sub grab(+@a) {};>
0 commit comments