On Tue, Sep 6, 2016 at 4:51 PM, Paul "LeoNerd" Evans <leonerd@leonerd.org.uk > wrote: > 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". Oh, and yield the same falsey value for a lhs that isn't a blessed reference, right? ;-) … okay, I'm sure someone reading this might not be aware that they already know this, so … eval { $SomeThing->DumbMatch($PretzelPattern } (Aside from $SIG{__DIE__}, damn it, the problem with this is if the string value of $SomeThing is a class name. But that problem was there ever since the method dispatch hammer was chosen for this particular nail.) EirikThread Previous | Thread Next