May 2019
Beginner to intermediate
466 pages
10h 44m
English
Function arguments can have sensible defaults. For such situations, Julia allows defining default values. When they are provided, the corresponding arguments no longer have to be passed explicitly on every call:
julia> function addremove(x=100, y=10)
x+y, x-y
end
addremove (generic function with 3 methods)
This function has default values for both x and y. We can invoke it without passing any of the arguments:
julia> addremove() (110, 90)
This snippet demonstrates how Julia uses the default values when they are not provided upon function invocation.
We can pass the first argument only—and for the second one, the default value will be used:
julia> addremove(5) (15, -5)
Finally, we can pass both arguments; all the defaults ...
Read now
Unlock full access