I don't see this being very useful:
>perl -E"my @a = qw( 10 20 30 ); say @a ~~ 0+\@a ? 'match' : 'no match'"
match
Is there any objections to change smart match such that
>perl -E"my @a = qw( 10 20 30 ); say @a ~~ 3 ? 'match' : 'no match'"
match
That's what people seem to expect from reading the docs, so you could even
say the current behaviour is buggy. I can write the patch if you're ok with
the change. If not, the docs need clarification.
ELB
I'm not really sure how useful @a ~~ $b is, but the docs from the
table on smart matching are clear: " Any Num numeric
equality $a == $b"
Thus, @a ~~ $b should be like @a == $b.
That seems to support your proposed change. However, I would suggest
adding an explicit "Array Num" case to perlsyn for clarity.
-- David
Yes, that's precisely what we want to avoid, by basing the dispatch on
the type of the right argument, in order to avoid surprising matches.
That's also how P6 does it. In a switch statement, one would expect a
C<when (3) {...}> clause not to be executed when the topic is an array
or an arrayref. But I fully agree that the @~~$ behaviour is not very
useful.
> In a switch statement, one would expect a
> C<when (3) {...}> clause not to be executed when the topic is an array
> or an arrayref.
A when(NUM) class *can* be executed when the topic is an array or an array
ref. What do you suggest should be changed?