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.[1][2]

Raku supports predicate dispatch using "where" clauses that can execute arbitrary code against any function or method parameter.[3]

Julia has a package for it with PatternDispatch.jl but otherwise natively supports multiple dispatch.

Experimental implementations have been created for Common LISP,[4][5] and for Java (JPred[2]).

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

edit
  1. ^ Millstein, T. Practical Predicate Dispatch (PDF). OOPSLA '05.
  2. ^ a b Millstein, T.; Frost, C.; Ryder, J.; Warth, A. (2009). "Expressive and modular predicate dispatch for Java". ACM Transactions on Programming Languages and Systems. 31 (2): 1. CiteSeerX 10.1.1.212.4268. doi:10.1145/1462166.1462168. S2CID 2150617.
  3. ^ "class Signature". Retrieved 2020-07-07.
  4. ^ "Predicate Dispatching in Common Lisp Object System" (PDF). publications.ai.mit.edu (FTP). (To view documents see Help:FTP)
  5. ^ "pcostanza/filtered-functions". GitHub. Retrieved 2016-04-07.
edit


📚 Artikel Terkait di Wikipedia

Multiple dispatch

multiple dispatch with a syntax similar to the above example. It was later replaced by PyProtocols. The Reg library also supports multiple and predicate dispatch

Static dispatch

In computing, static dispatch is a form of polymorphism fully resolved during compile time. It is a form of method dispatch, which describes how a language

Dynamic dispatch

In computer science, dynamic dispatch is the process of selecting which implementation of a polymorphic operation (method or function) to call at run time

Double dispatch

In software engineering, double dispatch is a special form of multiple dispatch, and a mechanism that dispatches a function call to different concrete

Subtyping

conjunction of predicates has been expressed here through application of the second predicate over the domain of values conforming to the first predicate. Viewed

Operator overloading

Environment. Oracle Corporation. Completely new operators can be added. "Predicate op/3". "Bertrand Meyer: Basic Eiffel language mechanisms". se.ethz.ch

Virtual function

virtual method is an inheritable and overridable function or method that is dispatched dynamically. Virtual functions are an important part of (runtime) polymorphism

Generic function

functions refers to a mechanism for compile-time polymorphism (static dispatch), specifically parametric polymorphism. These are functions defined with