Generic functions and multiple dispatch

We have already seen that functions are inherently defined as generic, that is, they can be used for different types of their arguments. The compiler will generate a separate version of the function each time it is called with arguments of a new type. In Julia, a concrete version of a function for a specific combination of argument types is called a method. To define a new method for a function (also called overloading), just use the same function name but a different signature, that is, with different argument types. A list of all the methods is stored in a virtual method table (vtable) on the function itself; methods do not belong to a particular type. When a function is called, Julia will lookup ...

Get Julia 1.0 Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.