Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

ARRAY ~~ NUM

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


ikegami at adaelis

Nov 22, 2009, 3:58 PM

Post #1 of 4 (313 views)
Permalink
ARRAY ~~ NUM

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


xdaveg at gmail

Nov 22, 2009, 4:11 PM

Post #2 of 4 (303 views)
Permalink
Re: ARRAY ~~ NUM [In reply to]

On Sun, Nov 22, 2009 at 6:58 PM, Eric Brine <ikegami [at] adaelis> 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


rgs at consttype

Nov 23, 2009, 12:57 AM

Post #3 of 4 (311 views)
Permalink
Re: ARRAY ~~ NUM [In reply to]

2009/11/23 Eric Brine <ikegami [at] adaelis>:
> 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.


ikegami at adaelis

Nov 23, 2009, 10:58 AM

Post #4 of 4 (289 views)
Permalink
Re: ARRAY ~~ NUM [In reply to]

On Mon, Nov 23, 2009 at 3:57 AM, Rafael Garcia-Suarez <rgs [at] consttype>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?

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.