Skip to content

Commit

Permalink
Comments >> on list of Callables, closes #1643
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Apr 12, 2019
1 parent b2367a3 commit daee46f
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions doc/Language/operators.pod6
Expand Up @@ -281,15 +281,29 @@ X<|»=«>
X<|«=»>
=head1 X<<<Hyper operators|hyper,<<;hyper,>>;hyper,«;hyper,»;>>>
Hyper operators include C<«> and C<»>, with their ASCII variants C«<<»
and C«>>». They apply a given operator enclosed (or preceded or followed, in the case of unary operators) by C<«> and/or C<»> to one or two
lists, returning the resulting list, with the pointy part of C<«> or C<»> aimed at the shorter list. Single elements are turned to a list, so they can be used too. If one of
the lists is shorter than the other, the operator will cycle over the shorter
list until all elements of the longer list are processed.
Hyper operators include C<«> and C<»>, with their ASCII variants C«<<» and
C«>>». They apply a given operator enclosed (or preceded or followed, in the
case of unary operators) by C<«> and/or C<»> to one or two lists, returning the
resulting list, with the pointy part of C<«> or C<»> aimed at the shorter list.
Single elements are turned to a list, so they can be used too. If one of the
lists is shorter than the other, the operator will cycle over the shorter list
until all elements of the longer list are processed.
say (1, 2, 3) »*» 2; # OUTPUT: «(2 4 6)␤»
say (1, 2, 3, 4) »~» <a b>; # OUTPUT: «(1a 2b 3a 4b)␤»
say (1, 2, 3) »+« (4, 5, 6); # OUTPUT: «(5 7 9)␤»
say (&sin, &cos, &sqrt)».(0.5);
# OUTPUT: «(0.479425538604203 0.877582561890373 0.707106781186548)␤»
The last example illustrates how postcircumfix operators (in this case .()) can
also be hypered.
my @a = <1 2 3>;
my @b = <4 5 6>;
say (@a,@b)»[1]; # OUTPUT: «(2 5)␤»
In this case, it's the [postcircumfix
[]](/language/operators#index-entry-.%5B_%5D) which is being hypered.
Assignment metaoperators can be I<hyped>.
Expand All @@ -313,8 +327,8 @@ Hyper operators are defined recursively on nested arrays.
say -« [[1, 2], 3]; # OUTPUT: «[[-1 -2] -3]␤»
Also, methods can be called in an out of order, concurrent fashion. The
resulting list is in order. Note that all hyper operators are candidates for
autothreading and will cause tears if the methods have side effects. The
resulting list will be in order. Note that all hyper operators are candidates
for autothreading and will cause tears if the methods have side effects. The
optimizer has full reign over hyper operators, which is the reason that they
cannot be defined by the user.
Expand Down Expand Up @@ -385,8 +399,8 @@ X<|[] (reduction metaoperators)>X<|[+] (reduction metaoperators)>
=head1 Reduction metaoperators
The reduction metaoperator, C<[ ]>, reduces a list with the given infix
operator. It gives the same result as the L<reduce|/routine/reduce> routine - see there for
details.
operator. It gives the same result as the L<reduce|/routine/reduce> routine -
see there for details.
# These two are equivalent:
say [+] 1, 2, 3; # OUTPUT: «6␤»
Expand Down

0 comments on commit daee46f

Please sign in to comment.