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

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

Thread Previous | Thread Next
From:
hv
Date:
August 24, 2012 16:02
Subject:
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
201208242219.q7OMJfu23367@crypt.org
Damian Conway <damian@conway.org> wrote:
:Abigail observed:
:> Besides, if someone were to use:
:>
:>     $var ~~ $x;
:>
:> and $x could be a number or a regexp, but in one of the runs gets served
:> the above warning (because this time, the code path has printed out $x),
:> and changes it to:
:>
:>     $var ~~ 0 + $x;
:>
:> it ain't going to work well in case $x is a regexp (or a coderef, or has
:> overloaded ~~ but not +, or has overloaded +, or several other cases), is it?
:
:You're right. That's a problem. That's *the* problem.
:
:The correct long-term solution is for Perl to know what type a scalar
:actually contains, and not to subsequently lose that knowledge merely
:because of internal side-effects and optimizations of the implementation. :-(

This is the bit I'm really not convinced about. I feel there is
a significant difference between the language that has this:
  my($value) = ($line =~ /value=(\d+)/);  # yay, we got a number

and the one that has this:
  my($value) = ($line =~ /value=(\d+)/);  # yay, we got a number
  $value += 0;	# RT#314159: oops, *now* we got a number

The first of these expresses much that to me seems intrinsic to what
perl is. The second seems to throw out the DWIM with the bathwater.

Hugo

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