/
S03-operators.pod
4405 lines (3093 loc) · 146 KB
/
S03-operators.pod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=encoding utf8
=head1 TITLE
Synopsis 3: Perl 6 Operators
=head1 AUTHORS
Luke Palmer <luke@luqui.org>
Larry Wall <larry@wall.org>
=head1 VERSION
Created: 8 Mar 2004
Last Modified: 10 Jun 2009
Version: 168
=head1 Overview
For a summary of the changes from Perl 5, see L</Changes to Perl 5 operators>.
=head1 Operator precedence
Not counting terms and terminators, Perl 6 has 23 operator precedence
levels (same as Perl 5, but differently arranged). Here we list the
levels from "tightest" to "loosest", along with a few examples of
each level:
A Level Examples
= ===== ========
N Terms 42 3.14 "eek" qq["foo"] $x :!verbose @$array
L Method postfix .meth .+ .? .* .() .[] .{} .<> .«» .:: .= .^ .:
N Autoincrement ++ --
R Exponentiation **
L Symbolic unary ! + - ~ ? | +^ ~^ ?^ ^
L Multiplicative * / % +& +< +> ~& ~< ~> ?& div mod
L Additive + - +| +^ ~| ~^ ?| ?^
L Replication x xx
X Concatenation ~
X Junctive and & also
X Junctive or | ^
L Named unary sleep abs sin temp let
N Nonchaining infix but does <=> leg cmp .. ..^ ^.. ^..^
C Chaining infix != == < <= > >= eq ne lt le gt ge ~~ === eqv !eqv
X Tight and &&
X Tight or || ^^ // min max
R Conditional ?? !! ff fff
R Item assignment = := ::= => += -= **= xx= .=
L Loose unary true not
X Comma operator , p5=> :
X List infix Z minmax X X~ X* Xeqv ...
R List prefix print push say die map substr ... [+] [*] any $ @
X Loose and and andthen
X Loose or or xor orelse
X Sequencer <==, ==>, <<==, ==>>
N Terminator ; {...}, unless, extra ), ], }
Using two C<!> symbols below generically to represent any pair of operators
that have the same precedence, the associativities specified above
for binary operators are interpreted as follows:
Assoc Meaning of $a ! $b ! $c
===== =========================
L left ($a ! $b) ! $c
R right $a ! ($b ! $c)
N non ILLEGAL
C chain ($a ! $b) and ($b ! $c)
X list infix:<!>($a; $b; $c)
For unaries this is interpreted as:
Assoc Meaning of !$a!
===== =========================
L left (!$a)!
R right !($a!)
N non ILLEGAL
(In standard Perl there are no unaries that can take advantage of
associativity, since at each precedence level the standard operators
are either consistently prefix or postfix.)
Note that list associativity (X) only works between identical operators.
If two different list-associative operators have the same precedence,
they are assumed to be right-associative with respect to each other.
For example, the C<X> cross operator and the C<Z> zip operator both
have a precedence of "list infix", but:
@a X @b Z @c
is parsed as:
@a X (@b Z @c)
Similarly, if the only implementation of a list-associative operator
is binary, it will be treated as right associative.
The standard precedence levels attempt to be consistent in their
associativity, but user-defined operators and precedence levels may mix
right and left associative operators at the same precedence level.
If two conflicting operators are used ambiguously in the same
expression, the operators will be considered non-associative with
respect to each other, and parentheses must be used to disambiguoate.
If you don't see your favorite operator above, the following
sections cover all the operators in precedence order. Basic operator
descriptions are here; special topics are covered afterwards.
=head2 Term precedence
This isn't really a precedence level, but it's in here because no operator
can have tighter precedence than a term. See S02 for longer descriptions of
various terms. Here are some examples.
=over
=item *
C<Int> literal
42
=item *
C<Num> literal
3.14
=item *
Non-interpolating C<Str> literal
'$100'
=item *
Interpolating C<Str> literal
"Answer = $answer\n"
=item *
Generalized C<Str> literal
q["$100"]
qq["$answer"]
=item *
Heredoc
qq:to/END/
Dear $recipient:
Thanks!
Sincerely,
$me
END
=item *
Array composer
[1,2,3]
Provides list context inside. (Technically, it really provides a
"semilist" context, which is a semicolon-separated list of statements,
each of which is interpreted in list context and then concatenated
into the final list.)
=item *
Hash composer
{ }
{ a => 42 }
Inside must be either empty, or a single list starting with a pair or a hash,
otherwise you must use C<hash()> or C<%()> instead.
=item *
Closure
{ ... }
When found where a statement is expected, executes immediately. Otherwise
always defers evaluation of the inside scope.
=item *
Capture composer
\(@a,$b,%c)
An abstraction representing an argument list that doesn't yet know its context.
=item *
Sigiled variables
$x
@y
%z
$^a
$?FILE
@@slice
&func
&div:(Int, Int --> Int)
=item *
Sigils as contextualizer functions
$()
@()
%()
&()
@@()
=item *
Regexes in quote-like notation
/abc/
rx:i[abc]
s/foo/bar/
=item *
Transliterations
tr/a..z/A..Z/
Note ranges use C<..> rather than C<->.
=item *
Type names
Num
::Some::Package
=item *
Subexpressions circumfixed by parentheses
(1+2)
Parentheses are parsed on the inside as a semicolon-separated list
of statements, which (unlike the statements in a block) returns the results
of all the statements concatenated together as a C<List> of C<Capture>.
How that is subsequently treated depends on its eventual binding.
=item *
Function call with parens:
a(1)
In term position, any identifier followed immediately by a
parenthesized expression is always parsed as a term representing
a function call even if that identifier also has a prefix meaning,
so you never have to worry about precedence in that case. Hence:
not($x) + 1 # means (not $x) + 1
abs($x) + 1 # means (abs $x) + 1
=item *
Pair composers
:by(2)
:!verbose
=item *
Signature literal
:(Dog $self:)
=item *
Method call with implicit invocant
.meth # call on $_
.=meth # modify $_
Note that this may occur only where a term is expected. Where a
postfix is expected, it is a postfix. If only an infix is expected
(that is, after a term with intervening whitespace), C<.meth> is a
syntax error. (The C<.=meth> form is allowed there only because there
is a special C<.=> infix assignment operator that is equivalent in
semantics to the method call form but that allows whitespace between
the C<=> and the method name.)
=item *
Listop (leftward)
4,3, sort 2,1 # 4,3,1,2
As in Perl 5, a list operator looks like a term to the expression on
its left, so it binds tighter than comma on the left but looser than
comma on the right--see List prefix precedence below.
=back
=head2 Method postfix precedence
All method postfixes start with a dot, though the dot is optional
for subscripts. Since these are the tightest standard operator,
you can often think of a series of method calls as a single term that
merely expresses a complicated name.
See S12 for more discussion of single dispatch method calls.
=over
=item *
Standard single-dispatch method calls
$obj.meth
=item *
Variants of standard single-dispatch method call
$obj.+meth
$obj.?meth
$obj.*meth
In addition to the ordinary C<.> method invocation, there are variants
C<.*>, C<.?>, and C<.+> to control how multiple related methods of
the same name are handled.
=item *
Class-qualified method call
$obj.::Class::meth
$obj.Class::meth # same thing, assuming Class is predeclared
As in Perl 5, tells the dispatcher which class to start searching from,
not the exact method to call.
=item *
Mutating method call
$obj.=meth
The C<.=> operator does inplace modification of the object on the left.
=item *
Meta-method call
$obj.^meth
The C<.^> operator calls a class metamethod;
C<foo.^bar> is short for C<foo.HOW.bar>.
=item *
Method-like postcircumfixes
$routine.()
$array.[]
$hash.{}
$hash.<>
$hash.«»
The dotless forms of these have exactly the same precedences.
=item *
Dotted form of any other postfix operator
$x.++ # postfix:<++>($x)
=item *
Dotted postfix form of any other prefix operator
$x.:<++> # prefix:<++>($x)
=item *
There is specifically no C<< infix:<.> >> operator, so
$foo . $bar
will always result in a compile-time error indicating the user should
use C<< infix:<~> >> instead. This is to catch an error likely to
be made by Perl 5 programmers learning Perl 6.
=back
=head2 Autoincrement precedence
As in C, these operators increment or decrement the object in question
either before or after the value is taken from the object, depending on
whether it is put before or after. Also as in C, multiple references
to a single mutating object in the same expression may result in undefined
behavior unless some explicit sequencing operator is interposed.
See L</Sequence points>.
As with all postfix operators in Perl 6, no space is allowed between
a term and its postfix. See S02 for why, and for how to work around the
restriction with an "unspace".
As mutating methods, all these operators dispatch to the type of
the operand and return a result of the same type, but they are legal
on value types only if the (immutable) value is stored in a mutable
container. However, a bare undefined value (in a suitable C<Scalar>
container) is allowed to mutate itself into an C<Int> in order to
support the common idiom:
say $x unless %seen{$x}++;
Increment of a C<Str> (in a suitable container) works similarly to
Perl 5, but is generalized slightly.
A scan is made for the final alphanumeric sequence in
the string that is not preceded by a '.' character. Unlike in Perl 5, this
alphanumeric sequence need not be anchored to the beginning of the
string, nor does it need to begin with an alphabetic character;
the final sequence in the string matching C<< <!after '.'> <rangechar>+ >>
is incremented regardless of what comes before it.
The C<< <rangechar> >> character class is defined as that subset of
characters that Perl knows how to increment within a range, as defined
below.
The additional matching behaviors provide two useful benefits:
for its typical use of incrementing a filename, you don't have to
worry about the path name or the extension:
$file = "/tmp/pix000.jpg";
$file++; # /tmp/pix001.jpg, not /tmp/pix000.jph
Perhaps more to the point, if you happen to increment a string that ends
with a decimal number, it's likely to do the right thing:
$num = "123.456";
$num++; # 124.456, not 123.457
Character positions are incremented within their natural range for
any Unicode range that is deemed to represent the digits 0..9 or
that is deemed to be a complete cyclical alphabet for (one case
of) a (Unicode) script. Only scripts that represent their alphabet
in codepoints that form a cycle independent of other alphabets may
be so used. (This specification defers to the users of such a script
for determining the proper cycle of letters.) We arbitrarily define
the ASCII alphabet not to intersect with other scripts that make use
of characters in that range, but alphabets that intersperse ASCII letters are
not allowed.
If the current character in a string position is the final character
in such a range, it wraps to the first character of the range and
sends a "carry" to the position left of it, and that position is
then incremented in its own range. If and only if the leftmost
position is exhausted in its range, an additional character of the
same range is inserted to hold the carry in the same fashion as Perl 5,
so incrementing '(zz99)' turns into '(aaa00)' and incrementing
'(99zz)' turns into '(100aa)'.
The following Unicode ranges are some of the possible rangechar ranges.
For alphabets we might have ranges like:
A..Z # ASCII uc
a..z # ASCII lc
Α..Ω # Greek uc
α..ω # Greek lc (presumably skipping U+03C2, final sigma)
א..ת # Hebrew
etc. # (XXX out of my depth here)
For digits we have ranges like:
0..9 # ASCII
٠..٩ # Arabic-Indic
०..९ # Devangari
০..৯ # Bengali
੦..੯ # Gurmukhi
૦..૯ # Gujarati
୦..୯ # Oriya
etc.
Other non-script 0..9 ranges may also be incremented, such as
⁰..⁹ # superscripts (note, cycle includes latin-1 chars)
₀..₉ # subscripts
0..9 # fullwidth digits
Conjecturally, any common sequence may be treated as a cycle even if it does
not represent 0..9:
Ⅰ..Ⅻ # clock roman numerals uc
ⅰ..ⅻ # clock roman numerals lc
①..⑳ # circled digits 1..20
⒜..⒵ # parenthesize lc
⚀..⚅ # die faces 1..6
❶..❿ # dingbat negative circled 1..10
etc.
While it doesn't really make sense to "carry" such numbers when they
reach the end of their cycle, treating such values as incrementable may
be convenient for writing outlines and similar numbered bullet items.
(Note that we can't just increment unrecognized characters, because
we have to locate the string's final sequence of rangechars before knowing
which portion of the string to increment. Note also that all character
increments can be handled by lookup in a single table of successors
since we've defined our ranges not to include overlapping cycles.)
Perl 6 also supports C<Str> decrement with similar semantics, simply by
running the cycles the other direction. However, leftmost characters
are never removed, and the decrement fails when you reach a string like
"aaa" or "000".
Increment and decrement on non-<Str> types are defined in terms of the
C<.succ> and C<.pred> methods on the type of object in the C<Scalar>
container. More specifically,
++$var
--$var
are equivalent to
$var.=succ
$var.=pred
If the type does not support these methods, the corresponding increment
or decrement operation will fail. (The optimizer is allowed to assume
that the ordinary increment and decrement operations on integers will
not be overridden.)
Increment of a C<Bool> (in a suitable container) turns it true.
Decrement turns it false regardless of how many times it was
previously incremented. This is useful if your C<%seen> array is
actually a C<KeySet>, in which case decrement actually deletes it
from the C<KeySet>.
=over
=item *
Autoincrement C<< prefix:<++> >> or C<< postfix:<++> >> operator
$x++
++$x;
=item *
Autodecrement C<< prefix:<--> >> or C<< postfix:<--> >> operator
$x--
--$x
=back
=head2 Exponentiation precedence
=over
=item *
C<< infix:<**> >> exponentiation operator
$x ** 2
If the right argument is not a non-negative integer, the result is likely to
be an approximation. If the right argument is of an integer type,
exponentiation is at least as accurate as repeated multiplication on
the left side's type. (From which it can be deduced that C<Int**UInt>
is always exact, since C<Int> supports arbitrary precision.) If the
right argument is an integer represented in a non-integer type, the
accuracy is left to implementation provided by that type; there is
no requirement to recognize an integer to give it special treatment.
=back
=head2 Symbolic unary precedence
=over
=item *
C<< prefix:<?> >>, boolean context
?$x
Evaluates the expression as a boolean and returns C<True> if expression
is true or C<False> otherwise.
See "true" below for a low-precedence alternative.
=item *
C<< prefix:<!> >>, boolean negation
!$x
Returns the opposite of what C<?> would.
See "not" below for a low-precedence alternative.
=item *
C<< prefix:<+> >>, numeric context
+$x
Unlike in Perl 5, where C<+> is a no-op, this operator coerces to
numeric context in Perl 6. (It coerces only the value, not the
original variable.) For values that are not already considered
numeric, the narrowest appropriate type of C<Int>, C<Num>, or
C<Complex> will be returned; however, string containing two integers
separated by a C</> will be returned as a C<Rat>. Exponential notation
and radix notations are recognized.
=item *
C<< prefix:<-> >>, numeric negation
-$x
Coerces to numeric and returns the arithmetic negation of the resulting number.
=item *
C<< prefix:<~> >>, string context
~$x
Coerces the value to a string. (It only coerces the value, not the
original variable.)
=item *
C<< prefix:<|> >>, flatten object into arglist
| $capture
Interpolates the contents of the C<Capture> (or C<Capture>-like) value
into the current argument list as if they had been specified literally.
If the first argument of the capture is marked as an invocant but is used
in a context not expecting one, it is treated as an ordinary positional
argument.
=item *
C<< prefix:<+^> >>, numeric bitwise negation
+^$x
Coerces to integer and then does bitwise negation (complement) on the number.
=item *
C<< prefix:<~^> >>, string bitwise negation
~^$x
Coerces to string buffer and then does bitwise negation (complement)
on each element.
=item *
C<< prefix:<?^> >>, boolean bitwise negation
?^$x
Coerces to boolean and then flips the bit. (Same as C<!>.)
=item *
C<< prefix:<^> >>, upto operator
^$limit
Constructs a range of C<0 ..^ $limit> or locates a metaclass as a shortcut
for C<$limit.HOW>. See L</Range and RangeIterator semantics>.
=back
=head2 Multiplicative precedence
=over
=item *
C<< infix:<*> >>
$x*$y
Multiplication, resulting in wider type of the two.
=item *
C<< infix:</> >>
$numerator / $denominator
If either operand is of C<Num> type, converts both operands to C<Num>
and does division returning C<Num>. If the denominator is zero,
returns an object representing either C<+Inf>, C<NaN>, or C<-Inf>
as the numerator is positive, zero, or negative. (This is construed
as the best default in light of the operator's possible use within
hyperoperators and junctions. Note however that these are not
actually the native IEEE non-numbers; they are undefined values of the
"unthrown exception" type that happen to represent the corresponding
IEEE concepts, and if you subsequently try to use one of these values
in a non-parallel computation, it will likely throw an exception at
that point.)
If both operands are of integer type, you still get a C<Num>, but the
C<Num> type is allowed to do the division lazily; internally it may
store a C<Rat> until the time a value is called for. If converted
to C<Rat> directly no division ever need be done.
=item *
C<< infix:<div> >>, generic division
$numerator div $denominator
Dispatches to the C<< infix:<div> >> multi most appropriate to the operand
types. Policy on what to do about division by zero is up to the type,
but for the sake of hyperoperators and junctions those types that
can represent overflow (or that can contain an unthrown exception)
should try to do so rather than simply throwing an exception. (And in
general, other operators that might fail should also consider their
use in hyperops and junctions, and whether they can profitably benefit
from a lazy exception model.)
Use of C<div> on two C<Int> values results in a ratio of the C<Rat> type.
=item *
C<< infix:<%> >>, modulus
$x % $mod
Always floor semantics using C<Num> or C<Int>.
=item *
C<< infix:<mod> >>, generic modulus
$x mod $mod
Dispatches to the C<< infix:<mod> >> multi most appropriate to the operand types.
=item *
C<< infix:{'+&'} >>, numeric bitwise and
$x +& $y
Converts both arguments to integer and does a bitwise numeric AND.
=item *
C<< infix:{'+<'} >>, numeric shift left
$integer +< $bits
=item *
C<< infix:{'+>'} >>, numeric shift right
$integer +> $bits
By default, signed types do sign extension, while unsigned types do not, but
this may be enabled or disabled with a C<:signed> or C<:!signed> adverb.
=item *
C<< infix:<~&> >>, buffer bitwise and
$x ~& $y
=item *
C<< infix:{'~<'} >>, buffer bitwise shift left
$buf ~< $bits
=item *
C<< infix:{'~>'} >>, buffer bitwise shift right
$buf ~> $bits
Sign extension is not done by default but may be enabled with a C<:signed>
adverb.
=item *
C<< infix:<?&> >>, boolean bitwise and
$x ?& $y
=back
Any bit shift operator may be turned into a rotate operator with the
C<:rotate> adverb. If C<:rotate> is specified, the concept of
sign extension is meaningless, and you may not specify a C<:signed> adverb.
=head2 Additive precedence
=over
=item *
C<< infix:<+> >>, numeric addition
$x + $y
Microeditorial: As with most of these operators, any coercion or type
mismatch is actually handled by multiple dispatch. The intent is that
all such variants preserve the notion of numeric addition to produce a
numeric result, presumably stored in suitably "large" numeric type to
hold the result. Do not overload the C<+> operator for other purposes,
such as concatenation. (And please do not overload the bitshift
operators to do I/O.) In general we feel it is much better for you
to make up a different operator than overload an existing operator for
"off topic" uses. All of Unicode is available for this purpose.
=item *
C<< infix:<-> >>, numeric subtraction
$x - $y
=item *
C<< infix:<+|> >>, numeric bitwise inclusive or
$x +| $y
=item *
C<< infix:<+^> >> numeric bitwise exclusive or
$x +^ $y
=item *
C<< infix:<~|> >>, buffer bitwise inclusive or
$x ~| $y
=item *
C<< infix:<~^> >> buffer bitwise exclusive or
$x ~^ $y
=item *
C<< infix:<?|> >>, boolean bitwise inclusive or
$x ?| $y
=item *
C<< infix:<?^> >> boolean bitwise exclusive or
$x ?^ $y
=back
=head2 Replication
=over
=item *
C<< infix:<x> >>, string/buffer replication
$string x $count
Evaluates the left argument in string context, replicates the resulting
string value the number of times specified by the right argument and
returns the result as a single concatenated string regardless of context.
If the count is less than 1, returns the null string.
The count may not be C<*> because Perl 6 does not support
infinite strings. (At least, not yet...) Note, however, that an
infinite string may be emulated with C<cat($string xx *)>.
=item *
C<< infix:<xx> >>, list replication
@list xx $count
Evaluates the left argument in list context, replicates the resulting
C<Capture> value the number of times specified by the right argument and
returns the result in a context dependent fashion. If the operator
is being evaluated in ordinary list context, the operator returns a
flattened list. In slice (C<@@>) context, the operator converts each C<Capture>
to a separate sublist and returns the list of those sublists.
If the count is less than 1, returns the empty list, C<()>.
If the count is C<*>, returns an infinite list (lazily, since lists
are lazy by default).
=back
=head2 Concatenation
=over
=item *
C<< infix:<~> >>, string/buffer concatenation
$x ~ $y
=back
=head2 Junctive and (all) precedence
=over
=item *
C<< infix:<&> >>, all() operator
$a & $b & $c ...
=item *
C<< infix:<also> >>, short-circuit junctional and operator
EXPR also EXPR also EXPR ...
Can be used to construct ANDed patterns with the same semantics as
C<< infix:<&> >>, but with left-to-right evaluation guaranteed, for use
in guarded patterns:
$target ~~ MyType also .mytest1 also .mytest2
This is useful when later tests might throw exceptions if earlier
tests don't pass. This cannot be guaranteed by:
$target ~~ MyType & .mytest1 & .mytest2
=back
=head2 Junctive or (any) precedence
=over
=item *
C<< infix:<|> >>, any() operator
$a | $b | $c ...
=item *
C<< infix:<^> >>, one() operator
$a ^ $b ^ $c ...
=back
=head2 Named unary precedence
Functions of one argument
sleep
abs
sin
... # see S29 Functions
Note that, unlike in Perl 5, you must use the C<.meth> forms to default
to C<$_> in Perl 6.
There is no unary C<rand> prefix in Perl 6, though there is a C<.rand>
method call and an argumentless C<rand> term. There is no unary C<int>
prefix either; you must use a typecast to a type such as C<Int> or C<int>.
(Typecasts require parentheses and may not be used as prefix operators.)
In other words:
my $i = int $x; # ILLEGAL
is a syntax error (two terms in a row), because C<int> is a type name now.
=over
=item *
C<< prefix:<int> >>
Coerces to type C<Int>. Floor semantics are used for fractional
values, including strings that appear to express fractional values.
That is, C<int($x)> must have the same result as C<int(+$x)> in all
cases. All implicit conversions to integer use the same semantics.