On Fri, Aug 17, 2012 at 03:24:10PM +0200, Abigail wrote: > On Thu, Aug 16, 2012 at 05:58:16PM -0400, Ricardo Signes wrote: > > > > So, last year I said "we really ought to cut most of smart match away." > > > > http://www.nntp.perl.org/group/perl.perl5.porters/2011/07/msg174272.html > > > > I've slept on it about 380 times, and I'm still for it. Here's the new plan: > > > > ## The New ~~ Operator > > > > $a $b Meaning > > ======= ======= ====================== > > Any undef ! defined $a > > Any ~~-overloaded ~~ overloading is used > > ~~-ol Any ~~ overloading is used (reversed) > > Any CodeRef, &{}-ol $b->($a) > > Any Regexp, qr-ol $a =~ $b > > Any Simple $a eq $b > > Any Any fatal > > > > This is a nearly a subset of the current behavior. Here are some major points: > > > > (1) This is ordered for the sake of knowing which overload to use first. > > > > (2) A simple scalar (non-reference, non-glob, non-vstring) on the rhs is > > used for stringwise equality. I have not yet seen any convincing argument > > that we can correctly intuit an eq/== behavior, so we pick one. > > For me, one of the few advantages I saw in using ~~ is not having to > wonder when to use == vs eq vs =~. The above table suggests that > > "0.0" ~~ 0 > > is false, while it's currently true. That bothers me. On the other hand, it makes a lot more sense to me. > IMO, a "smart match" > should be able to say, "hmmm, both my operands look like numbers, you know > what, I'll use '==' to compare them!" > > Would this be workable: > > $a $b Meaning > ======= ======= ====================== > Any undef ! defined $a > Any ~~-overloaded ~~ overloading is used > ~~-ol Any ~~ overloading is used (reversed) > Any CodeRef, &{}-ol $b->($a) > Any Regexp, qr-ol $a =~ $b > Any Looks like number $a == $b (without a "isn't numeric" warning) > Any Simple $a eq $b > Any Any fatal Honestly, I really can't see myself actually using any version of smartmatch that actually has a "looks like number" test like that. It's just too hard to figure out what is actually going to happen to make it worthwhile for me to actually try to use. -doyThread Previous | Thread Next