# New Ticket Created by Alex Kapranoff # Please include the string: [perl #76206] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=76206 >
Since && and "and" are special-cased for short-circuiting automatic reduction does not happen. Here a simple patch "by analogy". Index: S03-metaops/reduce.t =================================================================== --- S03-metaops/reduce.t (revision 31194) +++ S03-metaops/reduce.t (working copy) @@ -111,6 +111,16 @@ is (~ [\||] 0, 0, 3, 4, 5), "0 0 3 3 3", "[\\||] works"; } +#?rakudo skip 'implement [&&] and [and]' +{ + my @array = (Mu, Mu, 0, 3, Mu, 5); + my @array1 = (2, 3, 4); + nok ([&&] @array), "[&&] works with 1 false"; + is ([&&] @array1), 4, "[&&] works"; + nok ([and] @array), "[and] works with 1 false"; + is ([and] @array1), 4, "[and] works"; +} + # not currently legal without an infix subscript operator # { # my $hash = {a => {b => {c => {d => 42, e => 23}}}}; diff --git a/src/core/operators.pm b/src/core/operators.pm index ecdd356..4ad0884 100644 --- a/src/core/operators.pm +++ b/src/core/operators.pm @@ -553,10 +553,12 @@ our multi sub infix:<X>($a, $b) { &infix:<X>($a.list, $b.list) } # if we want &infix:<||> accessible (for example for meta operators), we need # to define it, because the normal || is short-circuit and special cased by -# the grammar. Same goes for 'or' +# the grammar. Same goes for 'or', '&&' and 'and' our multi sub infix:<||>(Mu $a, Mu $b) { $a || $b } our multi sub infix:<or>(Mu $a, Mu $b) { $a or $b } +our multi sub infix:<&&>(Mu $a, Mu $b) { $a && $b } +our multi sub infix:<and>(Mu $a, Mu $b) { $a and $b } # Eliminate use of this one, but keep the pir around for # the moment, as it may come in handy elsewhere. -- Alex Kapranoff.