Generic functions and multiple dispatch
We already saw 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. A concrete version of a function for a specific combination of argument types is called a method in Julia. 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 do a lookup in that ...
Get Julia: High Performance 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.