diff --git a/doc/Language/operators.pod b/doc/Language/operators.pod index cd0bc0034..db1eaa403 100644 --- a/doc/Language/operators.pod +++ b/doc/Language/operators.pod @@ -188,7 +188,7 @@ the blunt end at the list to be operated on. my @wisdom = True, False, True; say !« @wisdom; # [False True False] - + my @a = 1,2,3; @a»++; # (2,3,4) @@ -220,8 +220,8 @@ C<%foo »+« %bar;> union of keys C<%outer »+» %inner;> only keys of %inner that exist in %outer will occur in the result =end table - my %outer = 1,2,3 Z=> ; - my %inner = 1,2 Z=> ; + my %outer = 1,2,3 Z=> ; + my %inner = 1,2 Z=> ; say %outer «~» %inner; # {"1" => "ax", "2" => "bz"} Hyper operators can take user defined operators as its operator argument. @@ -231,7 +231,7 @@ Hyper operators can take user defined operators as its operator argument. sub infix:(Int \i1, Int \i2) { round(i1 / i2, 0.1) } - + # we build a vector of fractions of $size and zip that with the fitting prefix for $size «[r/]« (2**60, 2**50, 2**40, 2**30, 2**20, 2**10) Z -> [\v,\suffix] { @@ -241,7 +241,7 @@ Hyper operators can take user defined operators as its operator argument. # this be smaller or equal then 0.4 KB return $size.Str; } - + for 60, 50, 40, 30, 20, 10 -> $test { my &a = { (2 ** $test) * (1/4, 1/2, 1, 10, 100).pick * (1..10).pick }; print pretty-file-site(a.Int) xx 2, ' '; @@ -253,7 +253,7 @@ Hyper operators do not descent into child lists. You can chain hyper operators to destructure a List of Lists. my $neighbors = ((-1, 0), (0, -1), (0, 1), (1, 0)); - my $p = (2,3); + my $p = (2,3); say $neighbors »>>+<<» ($p, *); # ((1 3) (2 2) (2 4) (3 3)) =head2 Reduction Operators @@ -263,12 +263,12 @@ element by element and return the resulting value. say [+] 1,2,3; # 6 -They can be defined as a list prefix operators or will be generated automatically. +They can be defined as a list prefix operators or will be generated automatically. - multi infix:<[~~]> (@c, &test) is looser(&infix:<~~>) { - gather for @c { take $_ if test($_) } - }; - my @l = 1,'a',2,'b'; + multi infix:<[~~]> (@c, &test) is looser(&infix:<~~>) { + gather for @c { take $_ if test($_) } + }; + my @l = 1,'a',2,'b'; say @l [~~] {$^a ~~ Str}; # (a b) For list infix operators, flattening is not done on the input list. This @@ -278,7 +278,7 @@ allows list operators to become the reduction operator. By default reduction meta operators are eager. To lazily generate values, prefix the operator with a C<\>. If the non-meta part contains a C<\> already, -quote it with C<[]> (e.g. C<[\[\x]]>). +quote it with C<[]> (e.g. C<[\[\x]]>). my $lazy := [\+] 1..*; say $lazy[^10]; # (1 3 6 10 15 21 28 36 45 55) @@ -298,12 +298,12 @@ The zip metaoperator, C, will apply a given infix operator to pairs taken one left, one right, from its arguments. The resulting list is returned. my @l = Z~ 1,2,3; # [a1 b2 c3] - + If one of the operands runs out of elements prematurely, the zip operator will -stop. An infinite list can be used to repeat elements. A list with a final +stop. An infinite list can be used to repeat elements. A list with a final element of C<*> will repeat its 2nd last element indefinitely. - my @l = Z~ ':' xx *; # + my @l = Z~ ':' xx *; # my @l = Z~ 1, 2, *; # =head2 Sequential Operators @@ -318,9 +318,9 @@ done by the optimizer. Most simple infix operators are supported. To avoid ambiguity when chaining meta operators use square brackets to help the compiler to understand you. - my @a = 1,2,3; - my @b = 5,6,7; - @a X[+=] @b; + my @a = 1,2,3; + my @b = 5,6,7; + @a X[+=] @b; say @a; # [19 20 21] =head1 Z<>Term Precedence @@ -537,6 +537,7 @@ method call. 1.i # No such method 'i' for invocant of type 'Int' Technically this is not an operator, but syntax special-cased in the compiler. +X<|postfix call> =head2 postfix C«.:» @@ -547,6 +548,7 @@ A prefix can be called like a method using colonpair notation. For example: say $a.:<++>; # 3 Technically this is not an operator, but syntax special-cased in the compiler. +X<|prefix call> =head2 postfix C«.::» diff --git a/doc/Language/setbagmix.pod b/doc/Language/setbagmix.pod index c0fa559c3..f16538930 100644 --- a/doc/Language/setbagmix.pod +++ b/doc/Language/setbagmix.pod @@ -98,18 +98,24 @@ only C arguments. multi sub infix:<(elem)>($a, Any $b --> Bool) multi sub infix:<(elem)>($a, Set $b --> Bool) +X. + Returns C if C<$a> is an B of C<$b>. =head4 infix ∈ only sub infix:<<"∈">>($a, $b --> Bool) +X (alternate). + Equivalent to L«(elem)», at codepoint U+2208 (ELEMENT OF). =head4 infix ∉ only sub infix:<<"∉">>($a, $b --> Bool) +X. + Equivalent to C, i.e., returns C if C<$a> is not an element of C<$b>, at codepoint U+2209 (NOT AN ELEMENT OF). @@ -118,18 +124,24 @@ of C<$b>, at codepoint U+2209 (NOT AN ELEMENT OF). multi sub infix:<(cont)>(Any $a, $b --> Bool) multi sub infix:<(cont)>(Set $a, $b --> Bool) +X. + Returns C if C<$a> B C<$b> as an element. =head4 infix ∋ only sub infix:<<"∋">>($a, $b --> Bool) +X (alternate). + Equivalent to L«(cont)», at codepoint U+220B (CONTAINS AS MEMBER). =head4 infix ∌ only sub infix:<<"∌">>($a, $b --> Bool) +X. + Equivalent to C, i.e., returns C if C<$a> does not contain C<$b>, at codepoint U+220C (DOES NOT CONTAIN AS MEMBER). @@ -138,6 +150,8 @@ C<$b>, at codepoint U+220C (DOES NOT CONTAIN AS MEMBER). multi sub infix:<<(<=)>>(Any $a, Any $b --> Bool) multi sub infix:<<(<=)>>(Setty $a, Setty $b --> Bool) +X. + Returns C if C<$a> is a B or is equal to C<$b>, i.e., if all the elements of C<$a> are elements of C<$b> and C<$a> is a smaller or equal sized set than C<$b>. @@ -146,12 +160,16 @@ sized set than C<$b>. only sub infix:<<"⊆">>($a, $b --> Bool) +X (alternate). + Equivalent to L«(<=)», at codepoint U+2286 (SUBSET OF OR EQUAL TO). =head4 infix ⊈ only sub infix:<<"⊈">>($a, $b --> Bool) +X. + Equivalent to C«!(<=)», at codepoint U+2288 (NEITHER A SUBSET OF NOR EQUAL TO). =head3 infix (<) @@ -159,6 +177,8 @@ Equivalent to C«!(<=)», at codepoint U+2288 (NEITHER A SUBSET OF NOR EQUAL TO) multi sub infix:<<(<)>>(Any $a, Any $b --> Bool) multi sub infix:<<(<)>>(Setty $a, Setty $b --> Bool) +X. + Returns C if C<$a> is a B of C<$b>, i.e., that all the elements of C<$a> are elements of C<$b> but C<$a> is a smaller set than C<$b>. @@ -167,12 +187,16 @@ C<$b>. only sub infix:<<"⊂">>($a, $b --> Bool) +X (alternate). + Equivalent to L«(<)», at codepoint U+2282 (SUBSET OF). =head4 infix ⊄ only sub infix:<<"⊄">>($a, $b --> Bool) +X. + Equivalent to C«!(<)», at codepoint U+2284 (NOT A SUBSET OF). =head3 infix (>=) @@ -180,6 +204,8 @@ Equivalent to C«!(<)», at codepoint U+2284 (NOT A SUBSET OF). multi sub infix:<<(>=)>>(Any $a, Any $b --> Bool) multi sub infix:<<(>=)>>(Setty $a, Setty $b --> Bool) +X. + Like L«(<=)» with reversed arguments. Returns C if C<$a> is a B of or equal to C<$b>. @@ -187,12 +213,16 @@ B of or equal to C<$b>. only sub infix:<<"⊇">>($a, $b --> Bool) +X (alternate). + Equivalent to L«(>=)», at codepoint U+2287 (SUPERSET OF OR EQUAL TO). =head4 infix ⊉ only sub infix:<<"⊉">>($a, $b --> Bool) +X. + Equivalent to C«!(>=)», at codepoint U+2289 (NEITHER A SUPERSET OF NOR EQUAL TO). @@ -201,6 +231,8 @@ NOR EQUAL TO). multi sub infix:<<(>)>>(Any $a, Any $b --> Bool) multi sub infix:<<(>)>>(Setty $a, Setty $b --> Bool) +X. + Like L«(<)» with reversed arguments. Returns C if C<$a> is a B of C<$b>. @@ -208,12 +240,16 @@ B of C<$b>. only sub infix:<<"⊃">>($a, $b --> Bool) +X (alternate). + Equivalent to L«(>)», at codepoint U+2283 (SUPERSET OF). =head4 infix ⊅ only sub infix:<<"⊅">>($a, $b --> Bool) +X. + Equivalent to C«!(>)», at codepoint U+2285 (NOT A SUPERSET OF). =head3 infix (<+) @@ -221,6 +257,8 @@ Equivalent to C«!(>)», at codepoint U+2285 (NOT A SUPERSET OF). multi sub infix:<<(<+)>>(Any $a, Any $b --> Bool) multi sub infix:<<(<+)>>(Baggy $a, Baggy $b --> Bool) +X. + Returns C if C<$a> is a Baggy B of C<$b>, i.e., if all the elements of C<$a> are in C<$b> and each element of C<$b> is weighed at least as heavily as the element is in C<$a>. @@ -229,6 +267,8 @@ least as heavily as the element is in C<$a>. only sub infix:<<"≼">>($a, $b --> Bool) +X (alternate). + Equivalent to L«(<+)», at codepoint U+227C (PRECEDES OR EQUAL TO). =head3 infix (>+) @@ -236,6 +276,8 @@ Equivalent to L«(<+)», at codepoint U+227C (PRECEDES OR EQUAL TO). multi sub infix:<<(>+)>>(Baggy $a, Baggy $b --> Bool) multi sub infix:<<(>+)>>(Any $a, Any $b --> Bool) +X. + Returns C if C<$a> is a Baggy B of C<$b>, i.e., if all the elements of C<$b> are in C<$a> and no element of C<$b> is weighted heavier than that element is in C<$a>. @@ -244,6 +286,8 @@ than that element is in C<$a>. only sub infix:<<"≽">>($a, $b --> Bool) +X (alternate). + Equivalent to L«(+>)», at codepoint U+227D (SUCCEEDS OR EQUAL TO). =head2 Operators that return C or C @@ -252,6 +296,9 @@ Equivalent to L«(+>)», at codepoint U+227D (SUCCEEDS OR EQUAL TO). only sub infix:<(|)>(**@p) + +X. + Returns the B of all its arguments. Generally, this creates a new C that contains all the elements its arguments contain. @@ -267,12 +314,16 @@ appeared for that element. only sub infix:<<"∪">>(|p) +X (alternate). + Equivalent to L«(V<|>)», at codepoint U+222A (UNION). =head3 infix (&) only sub infix:<(&)>(**@p) +X. + Returns the B of all of its arguments. Generally, this creates a new C that contains only the elements common to all of the arguments. @@ -289,12 +340,17 @@ is the minimum of the weights of that element over all arguments). only sub infix:<<"∩">>(|p) +X (alternate). + Equivalent to L«(&)», at codepoint U+2229 (INTERSECTION). =head3 infix (-) only sub infix:<(-)>(**@p) + +X. + Returns the B of all its arguments. Generally, this returns the C made up of all the elements the first argument has but the rest don't, i.e., of all the elements of the first argument, minus the elements @@ -311,6 +367,8 @@ that element in each of the other arguments. only sub infix:<<"\x2216">>(|p) +X (alternate). + Equivalent to L«(-)». =head3 infix (^) @@ -318,6 +376,9 @@ Equivalent to L«(-)». multi sub infix:<(^)>(Any $a, Any $b --> Setty) multi sub infix:<(^)>(Set $a, Set $b --> Setty) + +X. + Returns the B of all its arguments, i.e., a C made up of all the elements that C<$a> has but C<$b> doesn't and all the elements C<$b> has but C<$a> doesn't. Equivalent to C<($a ∖ $b) ∪ ($b ∖ @@ -327,12 +388,16 @@ $a)>. only sub infix:<<"⊖">>($a, $b --> Setty) +X (alternate). + Equivalent to L«(^)», at codepoint U+2296 (CIRCLED MINUS). =head3 infix (.) only sub infix:<(.)>(**@p) +X. + Returns the Baggy B of its arguments, i.e., a C that contains each element of the arguments with the weights of the element across the arguments multiplied together to get the new weight. @@ -344,12 +409,16 @@ across the arguments multiplied together to get the new weight. only sub infix:<<"⊍">>(|p) +X (alternate). + Equivalent to L«(.)», at codepoint U+228D (MULTISET MULTIPLICATION). =head3 infix (+) only sub infix:<(+)>(**@p) +X. + Returns the Baggy B of its arguments, i.e., a C that contains each element of the arguments with the weights of the element across the arguments added together to get the new weight. @@ -361,10 +430,12 @@ arguments added together to get the new weight. only sub infix:<<"⊎">>(|p) +X (alternate). + Equivalent to L«(+)», at codepoint U+228E (MULTISET UNION). =head3 term ∅ -Equivalent to set(), aka the empty set, at codepoint U+2205 (EMPTY SET). +Equivalent to set(), aka X, at codepoint U+2205 (EMPTY SET). =end pod