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

Re: pounding the smartmatch drum

Thread Previous | Thread Next
From:
David Nicol
Date:
September 6, 2016 02:24
Subject:
Re: pounding the smartmatch drum
Message ID:
CAFwScO8poJuWeeBTec_ctdoZhYOyw7Tcrf+8ogyfambbZy+4EQ@mail.gmail.com
>> The type of matching to
>> perform should be determined entirely by the rhs, and any type of
>> matching that amounts to "ask the lhs whether it matches" is too
>> surprising and not useful enough to warrant being a built-in matching
>> rule.

I agree. We already have a way to "ask the lhs whether it matches" and
that system is called method dispatch.

sub UNIVERSAL::DumbMatch{0}
sub DumbMatchOnOdd::DumbMatch{ [0,1]->[$_[1] % 2] }
...
$SomeObjectOrOther->DumbMatch($PretzelPattern) and say "got a pretzel";


-- 
"Teaching radical novelties is our main safeguard against
dictatorships" -- Edsger W. Dijkstra

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