Julia: Functions, methods, and signatures
1 Functions
In Julia, a function is a operation that can accept inputs and returns outputs. A function of a particular name (e.g. range, rand, my_custom_function) may have a number of different methods, or implementation that are distinguished by the pattern of arguments the function takes (called the signature of the function).
2 Methods
A method is a specific implementation of that function for particular input types or argument combinations. When you call rand(), rand(Int), or rand(1:6), you are calling different methods of the same function rand. Julia automatically selects the appropriate method based on the types and number of arguments you provide, as long as someone (the Julia programmers, package programmers, or yourself) has written a function that takes combination of arguments, a mechanism called multiple dispatch.
3 Signatures
Different methods of a functions are distiguished by their signature, which is the particular number (“arity”), order, and type of arguments: e.g.
foo(a, b)foo(a::Int, b::String, c::Float64)foo(a::Float64, b::Int)
Note that the names of the arguments do not matter, and the following all have the same signature:
foo(a::Int, b::Float64)foo(first_input::Int, second_input::Float64)