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

Re: smartmatch needs your eyes

Thread Previous | Thread Next
From:
Ricardo Signes
Date:
September 21, 2015 13:36
Subject:
Re: smartmatch needs your eyes
Message ID:
20150921133645.GA20176@cancer.codesimply.com

This whole subthread is rebuilding my resolve.  Plain scalars should go pound
sand.  I don't believe I'll see a way to use them on the rhs of ~~ that will be
straightforward.

I think we're better off with helpers to build tests, like Smart::Match.

  sub smartgrep ($test, @items) { return grep { $_ ~~ $test } @items; }

If we want the test to be numeric, we can call:

  smartgrep num(4), @input;

Making that faster than 0+@input subroutine calls should be possible in the
future if someone decides it's worth doing.

Meanwhile, we have:

  when { $_ == 1 } { ... }

...which is still shorter than:

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

Also, if we disallow "when (5)" now, it can be enabled later, but if we allow
it now, we're stuck with it.

That was the plan when I first posted to this thread, and I don't know why I
got distracted by this idea that I'd already dismissed ages ago.

-- 
rjbs

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