develooper Front page | perl.perl5.porters | Postings from August 2012

Re: fixing smartmatch just hard enough (and when, too)

Thread Previous | Thread Next
From:
Peter Scott
Date:
August 31, 2012 13:05
Subject:
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
504118E5.4080909@PSDT.com
On 8/31/2012 7:20 AM, Ricardo Signes wrote:
> * Peter Scott <Peter@PSDT.com> [2012-08-30T01:40:35]
> I feel the same way, which is why I originally and again proposed the 
> much simpler behavior discussed in this thread.
>> If I wanted to construct a subroutine that smartmatched arguments that
>> could really be of any type, I'd be so paranoid every time I looked at
>> the code that I'd be forever reconsidering what all possible argument
>> types could do.  Is the type dispatch table for ~~ obvious enough that
>> people can internalize it rapidly without having to refer to it
>> constantly?  So far, I haven't.
> ...because this paragraph made it sound like you were only considering the old
> one.  The new one is tiny and (I thought) both easy to remember and to intuit.
> Could you let me know whether you've written ths message with it in mind?

Both actually, but for different reasons (see below).

> Again, the current discussion does not allow $x ~~ $simple_value. 

I'm afraid I have gotten lost among the proposals.  The original one in 
this thread included:

     Any     Simple              $a eq $b

got whittled down to "unambigous Num/str", but I missed the part where 
that was removed altogether.  FC's post of restricting ~~ to *only* 
Scalar/Simple was where I chimed in, although perhaps I missed a nuance 
in how he proposed special-casing it.

>> If there were a natural intuitive interpretation of ~~ I think it would
>> have emerged from all this brainstorming by now.
> I think one has.  Are you specifically saying that the "short table smart
> match" is not good?  Because it's too complex, or too simple?
>
> It was:
>
>    $x ~~ undef
>    $x ~~ $overloaded_object
>    $x ~~ sub {}
>    $x ~~ regex
>    ...or fail

I objected to the original/current table for the same reasons AFAICT as 
you do.  I'm afraid that your proposal, while much smaller and probably 
memorable, if it doesn't include a Simple case, will spawn a neverending 
chorus of "Why can't I do 'when (42)'?"  That seems to be the *only* use 
case that some people want ~~ for and it seems quite reasonable for them 
to want it.  Yet I can't see the Simple case working because of the 
string/number dichotomy that has been hashed over and over.  And if they 
*can* do when(42) then they will want to do when($ULTIMATE_ANSWER) and 
when(ULTIMATE_ANSWER) and if they can't, it becomes embarrassing to try 
and explain why.

Despite heroic efforts by yourself and equally stellar minds, I think 
this tunnel has no light at its end.  IMHO.  Sorry.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About