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

Re: smartmatch needs your eyes

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
October 6, 2015 19:58
Subject:
Re: smartmatch needs your eyes
Message ID:
20151006195750.GE16789@iabyn.com
On Tue, Oct 06, 2015 at 01:39:25PM -0400, Ricardo Signes wrote:
> * Dave Mitchell <davem@iabyn.com> [2015-10-06T12:03:30]
> > So for final clarity, is
> > 
> >     when (EXPR) {...}
> > 
> > intended to always be exactly equal to 
> > 
> >    if ($_ =~ EXPR) {...; break }
> 
> Yes.
> 
> > If so, how does one write something functionally equivalent to when(1)
> > now?
> 
> when { $_ == 1 } { ... }

But by the definition above, that is equivalent to 

    if ($_ =~ ($_ == 1)) {...; break }


On Tue, Oct 06, 2015 at 02:47:47PM -0400, Eric Brine wrote:
> On Tue, Oct 6, 2015 at 12:03 PM, Dave Mitchell <davem@iabyn.com> wrote:
> > If so, how does one write something functionally equivalent to when(1)
> > now?
> >
> 
> You need a helper that returns an object that overrides smartmatch.
> 
> when (num(1))

I guess this is the correct answer. In which case, yuck. We seem to have
thrown the baby out with the bath water :-(.


-- 
"You may not work around any technical limitations in the software"
    -- Windows Vista license

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