Skip to content

Commit ee39d98

Browse files
committed
Added entry on Reduction operators to operators.pod
1 parent 1f5b4de commit ee39d98

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/Language/operators.pod

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,29 @@ roles).
15341534
If the C<???> statement is executed, it calls L<&warn>, with the default
15351535
message C<stub code executed>.
15361536
1537+
=head2 Reduction operators
1538+
1539+
Any infix operator (except for non-associating operators) can be
1540+
surrounded by square brackets in term position to create a list operator
1541+
that reduces using that operation.
1542+
1543+
=begin code
1544+
1545+
[+] 1, 2, 3; # 1 + 2 + 3 = 6
1546+
my @a = (5,6);
1547+
[*] @a; # 5 * 6 = 30
1548+
1549+
=end code
1550+
1551+
Reduction operators have the same associativity as the operators they are based on.
1552+
1553+
=begin code
1554+
1555+
[-] 4, 3, 2; # 4-3-2 = (4-3)-2 = -1
1556+
[**] 4, 3, 2; # 4**3**2 = 4**(3**2) = 262144
1557+
1558+
=end code
1559+
15371560
=head1 Loose AND precedence
15381561
15391562
=head2 infix C«and»

0 commit comments

Comments
 (0)