Book Image

Mastering Julia

Book Image

Mastering Julia

Overview of this book

Table of Contents (17 chapters)
Mastering Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Multiple dispatch


A function is an object that maps a tuple of arguments to a return value. In a case where the arguments are not valid, the function should handle the situation cleanly by catching the error and handling it or throw an exception.

When a function is applied to its argument tuple, it selects the appropriate method and this process is called dispatch. In traditional object-oriented languages, a method is chosen based only on the object type and this paradigm is termed single dispatch. With Julia, the combination of all function arguments determines which method is chosen; this is the basis of multiple dispatch.

To the scientific programmer, all this seems very natural. It makes little sense in most circumstances for one argument to be more important than the others. In Julia, all functions and operators (which are also functions) use multiple dispatch. The methods are chosen for any combination of operators.

For example, look at the methods of the power operator (^):

julia&gt...