Larry Wall wrote:
On Tue, Jul 20, 2010 at 11:53:27PM -0400, Mark J. Reed wrote:
: In particular, consider that pi ~~ 0..4 is true,
: because pi is within the range; but pi ~~ 0...4 is false, because pi
: is not one of the generated elements.
Small point here, it's not because pi is fractional: 3 ~~ 0...4 is
also false because 3 !eqv (0,1,2,3,4). There is no implicit any()
on a smartmatch list pattern as there is in Perl 5. In Perl 6 the
pattern 0..4 may only match a list with the same 5 elements in the
same order.
For some reason I thought smart match in Perl 6, when presented with some
collection on the right-hand side, would test if the value on the left-hand side
was contained in the collection.
So, for example:
my @ary = (1,4,3,2,9);
my $test = 3;
$test ~~ @ary; # TRUE
Similarly, since a range represents a set of all values between 2 endpoints, I
might have thought this would be reasonable:
3 ~~ 1..5 # TRUE
So if that doesn't work, then what is the canonical way to ask if a value is in
a range?
Would any of these be reasonable?
3 ~~ any(1..5)
3 in 1..5
3 ∈ 1..5 # Unicode alternative
-- Darren Duncan