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

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

Thread Previous | Thread Next
From:
Darin McBride
Date:
August 30, 2012 06:53
Subject:
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
2627903.dTUtE8SVKe@naboo
On Thursday August 30 2012 10:15:34 AM Johan Vromans wrote:
> Case (switch, select, ...) statements have always been intended to serve
> two purposes: the programmer and the compiler. To the programmer it
> provides a quick and hopefully elegant way to test something against
> several constant values. Constant is important for the second purpose,
> since it can be compiled into a very efficient branch table.

Disagreed.  The shell's case statement does not require constant values and is 
hugely beneficial because of it.

To the programmer, yes: quick and hopefully elegant way to test against 
several values.  If this doesn't quite allow an efficient branch table, that's 
unfortunate, but we already use hash-based dispatch tables for that.  And that 
already has to be constant values due to the nature of hashes.

And I do have code already that checks: do I have a scalar, an array ref, or a 
code ref, and basically smart-matches against them (code running in perl 
5.8.8).  I was looking forward to using ~~ here to not only simplify the code, 
but allow more match styles, effectively reducing the number of times we may 
need to supply a code ref as those are relatively bulky.
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