From: Rafael Garcia-Suarez Date: Tue, 12 May 2009 07:38:29 +0000 (+0200) Subject: Remove proposed (but unimplemented) $foo ~~ Range smart matching. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f118ea0d484695c3af550a63cea6055340ab67d7;p=p5sagit%2Fp5-mst-13.2.git Remove proposed (but unimplemented) $foo ~~ Range smart matching. The reasons for that are : - $_ ~~ 1..42 actually parses as ($_ ~~ 1) .. 42 - in when(), a range 1..42 will be expanded, and not treated as a boolean flip-flop operator - It will not distribute properly with array smart-matching, as in $foo ~~ [1, 2, [4..5]] (that won't match for $foo = 4.2 for example.) --- diff --git a/op.c b/op.c index f1faf42..93bbf21 100644 --- a/op.c +++ b/op.c @@ -5224,6 +5224,8 @@ S_looks_like_bool(pTHX_ const OP *o) case OP_DEFINED: case OP_EXISTS: case OP_MATCH: case OP_EOF: + case OP_FLOP: + return TRUE; case OP_CONST: @@ -5234,11 +5236,6 @@ S_looks_like_bool(pTHX_ const OP *o) return TRUE; else return FALSE; - - case OP_FLOP: - /* Detect "..." flip-flop operator */ - if (cUNOPo->op_first->op_flags & OPf_SPECIAL) - return TRUE; /* FALL THROUGH */ default: diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index 038bcfa..94a5677 100644 --- a/pod/perlsyn.pod +++ b/pod/perlsyn.pod @@ -603,8 +603,7 @@ that return numerical values, not boolean ones. =item * -the C<...> flip-flop operator (but B the two-dot version C<..>, which -is used to construct and test against numerical or string ranges). +the C<..> and C<...> flip-flop operators. =back @@ -718,11 +717,8 @@ and "Array" entries apply in those cases. (For blessed references, the Array Regex array grep grep /$b/, @$a Any Regex pattern match $a =~ /$b/ - undef Range[4] always false - Any Range[4] in range - Any Num numeric equality $a == $b - Num numish[5] numeric equality $a == $b + Num numish[4] numeric equality $a == $b Any Any string equality $a eq $b @@ -730,11 +726,7 @@ and "Array" entries apply in those cases. (For blessed references, the 2 - that is, each element smart-matches the element of same index in the other array. [3] 3 - If a circular reference is found, we fall back to referential equality. - 4 - a range is written EXPR..EXPR (using the C<..> range operator, but - NOT the three-dot version C<...>, which will be treated as a boolean - operator). Numeric ranges will use numeric comparison: that is, - "4.5 ~~ 3..5" will be true. - 5 - either a real number, or a string that looks like a number + 4 - either a real number, or a string that looks like a number The "matching code" doesn't represent the I matching code, of course: it's just there to explain the intended meaning. Unlike diff --git a/t/op/smartmatch.t b/t/op/smartmatch.t index eb14bf0..ab36cbf 100644 --- a/t/op/smartmatch.t +++ b/t/op/smartmatch.t @@ -379,8 +379,6 @@ __DATA__ 12345 qr/3/ ! 12345 qr/7/ -# TODO ranges - # array/hash against string @fooormore "".\@fooormore ! @keyandmore "".\@fooormore diff --git a/t/op/switch.t b/t/op/switch.t index 9ca4f13..79b3797 100644 --- a/t/op/switch.t +++ b/t/op/switch.t @@ -8,7 +8,7 @@ BEGIN { use strict; use warnings; -use Test::More tests => 118; +use Test::More tests => 122; # The behaviour of the feature pragma should be tested by lib/switch.t # using the tests in t/lib/switch/*. This file tests the behaviour of @@ -517,6 +517,17 @@ sub notfoo {"bar"} my $n = 0; for my $l qw(a b c d) { given ($l) { + when ($_ eq "b" .. $_ eq "c") { $n = 1 } + default { $n = 0 } + } + ok(($n xor $l =~ /[ad]/), 'when(E1..E2) evaluates in boolean context'); + } +} + +{ + my $n = 0; + for my $l qw(a b c d) { + given ($l) { when ($_ eq "b" ... $_ eq "c") { $n = 1 } default { $n = 0 } }