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

Re: pounding the smartmatch drum

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
September 6, 2016 14:51
Subject:
Re: pounding the smartmatch drum
Message ID:
20160906155118.78531578@shy.leonerd.org.uk
On Mon, 5 Sep 2016 21:23:54 -0500
David Nicol <davidnicol@gmail.com> wrote:

> 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";

Well, almost. That is a bit dirty and pollutes the UNIVERSAL namespace.

Nicer would be if perl had notations for "try to call this method but
if it doesn't exist, yield some sentinel falsey value like undef or
empty list".

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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