November 2017
Beginner
316 pages
6h 40m
English
Methods are a very important part of Julia's ecosystem. To better understand what multiple dispatch is and why Julia uses it, we need to get familiar with methods first.
Suppose we have a function that adds two numbers:
julia> function add_numbers(num1::Int64, num2::Int64) return num1 + num2 endadd_numbers (generic function with 1 method)
If you closely observe the function definition, we have defined the add_numbers() to take in two arguments. Both of them being integer values (Int64, as I am currently on a 64-bit machine). What happens when we call the function add_numbers(10,20)? We get the following result:
julia> add_numbers(10,20)30julia> typeof(ans)Int64
No surprises here, as 10+20 =30. Also, notice the type ...
Read now
Unlock full access