nmerriweather has asked for the wisdom of the Perl Monks concerning the following question:

A friend came back from pycon, and showed me some really cool implementations of the predicate dispatch model in python.

I looked around online, and couldn't find much of anything relating that practice to perl. Can anyone offer some links?

Replies are listed 'Best First'.
Re: predicate dispatching
by Corion (Patriarch) on Apr 06, 2005 at 06:59 UTC

    It would have been nice of you to shortly describe, what Predicate Dispatch is. At least according to what Google tells me, Predicate Dispatch seems to be (object/class) method dispatch based on functions ("predicates") that indicate which method is the most appropriate to dispatch to.

    The Perl5 dispatch mechanism has only single dispatch based on the object/class type, and Perl6 will have multimethod dispatch, based on all parameter types, as far as I understand. Implementing and (much more so) sensibly declaring Predicate Dispatch methods is something I haven't seen, but the most likely candidate for an implementation is Damian Conways book, ?Object Oriented Perl?.

Re: predicate dispatching
by nmerriweather (Friar) on Apr 06, 2005 at 17:05 UTC
Re: predicate dispatching
by dragonchild (Archbishop) on Apr 06, 2005 at 17:28 UTC
    So, basically what you're saying is that you want the ability to specify when a certain method should be called versus some other method at runtime. Sounds like a candidate for AUTOLOAD, but you're going to be doing a lot of book-keeping yourself. Also, you need to figure out the syntax for how you specify your predicates. Attributes might help you here, but they're not easy to work with.

    In other words, you figure out the API you want to use and we'll help you from there. Sounds like a great project. Good luck!