Predicate dispatch
{{Short description|Technique in computer programming}}
{{Polymorphism}}
In computer programming, predicate dispatch is a generalisation of multiple dispatch ("multimethods") that allows the method to call to be selected at runtime based on arbitrary decidable logical predicates and/or pattern matching attached to a method declaration.{{Cite conference | last1 = Millstein | first1 = T. | title = Practical Predicate Dispatch | conference = OOPSLA '05 | url=http://web.cs.ucla.edu/~todd/research/oopsla04.pdf}}{{Cite journal | last1 = Millstein | first1 = T. | last2 = Frost | first2 = C. | last3 = Ryder | first3 = J. | last4 = Warth | first4 = A. | title = Expressive and modular predicate dispatch for Java | doi = 10.1145/1462166.1462168 | journal = ACM Transactions on Programming Languages and Systems | volume = 31 | issue = 2 | pages = 1 | year = 2009 | citeseerx = 10.1.1.212.4268 | s2cid = 2150617 }}
Raku supports predicate dispatch using "where" clauses that can execute arbitrary code against any function or method parameter.{{cite web | title=class Signature | url=https://docs.raku.org/type/Signature#index-entry-where_clause | access-date=2020-07-07 }}
Julia has a package for it with [https://github.com/toivoh/PatternDispatch.jl PatternDispatch.jl] but otherwise natively supports multiple dispatch.
Experimental implementations have been created for Common LISP,{{Cite FTP | title=Predicate Dispatching in Common Lisp Object System | server=publications.ai.mit.edu | url=ftp://publications.ai.mit.edu/ai-publications/2001/AITR-2001-006.pdf}}{{Cite web|url=https://github.com/pcostanza/filtered-functions|title=pcostanza/filtered-functions|website=GitHub|access-date=2016-04-07}} and for Java (JPred).
It allows open extension of previously declared methods at a fine-grained level, but multiple extensions with identical or overlapping predicates created by different developers may interfere with each other in unanticipated ways. In this respect it is similar to aspect-oriented programming.
References
{{reflist}}
External links
- [https://wiki.c2.com/?PredicateDispatching= C2 wiki: Predicate dispatching]
Category:Method (computer programming)
Category:Polymorphism (computer science)
{{compu-prog-stub}}