develooper Front page | perl.perl5.porters | Postings from September 2015

Re: smartmatch needs your eyes

Thread Previous | Thread Next
From:
Zefram
Date:
September 10, 2015 15:54
Subject:
Re: smartmatch needs your eyes
Message ID:
20150910155429.GK12731@fysh.org
Ricardo Signes wrote:
>  # STEP TWO
>  $obj ~~ $x      -->     uses ~~ overloading if present, otherwise pass
...
>The change here is "Step Two."  I'm not particularly a fan of it, and would
>discourage it, but it has the practical benefit of keeping autodie working.

If this goes into blead, then this is the part that in years to come
we will look back on and ask "what were we thinking?".  Better to make
autodie handle the cleaner behaviour, if necessary with version-dependent
code paths.

>                 I am surprised that the result of the subroutine is returned
>  # as the result of the smart match ?????that is, that it is not forced into
>  # a boolean.  I think I'm going to mark that up as my problem, not perl's,
>  # but I'm still surprised. -- rjbs, 2015-09-09

This sounds rather like some recently-discussed features in the tied
hash system.  IIRC, someone wanted exists($h{$k}) to return whatever
the EXISTS method returns, whereas it actually returns a canonical-form
truth value.  The consensus there was that the concept of the exists
operator is fundamentally a predicate operation, and it's not meaningful
for it to return any information beyond a mere truth value.  Hence the
canonicalisation is a good thing.

Smartmatch is also fundamentally a predicate operation, and by the
same logic should also canonicalise its return value.  Likewise, if it
doesn't already, it should always call a sub or overloaded method in
scalar context.

-zefram

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