Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ARRAY ~~ NUM

0 views
Skip to first unread message

Eric Brine

unread,
Nov 22, 2009, 6:58:30 PM11/22/09
to perl5 porters
Hello,

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

David Golden

unread,
Nov 22, 2009, 7:11:35 PM11/22/09
to Eric Brine, perl5 porters
On Sun, Nov 22, 2009 at 6:58 PM, Eric Brine <ike...@adaelis.com> wrote:
>>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.

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

Rafael Garcia-Suarez

unread,
Nov 23, 2009, 3:57:27 AM11/23/09
to Eric Brine, perl5 porters
2009/11/23 Eric Brine <ike...@adaelis.com>:

> Hello,
>
> 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

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.

Eric Brine

unread,
Nov 23, 2009, 1:58:38 PM11/23/09
to Rafael Garcia-Suarez, perl5 porters
On Mon, Nov 23, 2009 at 3:57 AM, Rafael Garcia-Suarez <r...@consttype.org>wrote:

> 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?

0 new messages