I have seen much talk about predicate dispatch in Clojure lately and wonder if there is something to this thing. In other words, what is predicate dispatch and how does it differ from generic functions, OOP polymorphism, and patterns? Thank you
Predicate in general meaning is a statement about something that is either true or false. In programming, predicates represent single argument functions that return a boolean value.
Dispatch rule is a principle of contract law that an acceptance becomes effective and binds the offeror once it has been properly mailed. However, if the offer provides that an acceptance is not effective until received then, the dispatch rule does not apply.
Predicate dispatch subsumes generic functions, OOP polymorphism, pattern matching, and more. A good overview is Predicate dispatching: A unified theory of dispatch by Michael Ernst, Craig Kaplan, and Craig Chambers. From its abstract:
Predicate dispatching generalizes previous method dispatch mechanisms by permitting arbitrary predicates to control method applicability and by using logical implication between predicates as the overriding relationship. The method selected to handle a message send can depend not just on the classes of the arguments, as in ordinary object-oriented dispatch, but also on the classes of subcomponents, on an argument's state, and on relationships between objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With