November 2017
Beginner
316 pages
6h 40m
English
The "+" symbol is a function in Julia using multiple dispatch. Multiple dispatch is used by all of Julia's standard functions and operators. For the various possible combinations of argument types and counts, all of them have many methods defining their behavior. A method is restricted to taking certain types of arguments using the ::type-assertion operator:
julia> f(x::Float64, y::Float64) = x + y f (generic function with 1 method)
The function definition will only be applied for calls where x and y are both values of the Float64 type:
julia> f(10.0, 14.0) 24.0
If we try to apply this definition to other types of arguments, it will give a method error:
julia> f(5,10.0)ERROR: MethodError: no method matching f(::Int64, ...
Read now
Unlock full access