November 2017
Beginner
316 pages
6h 40m
English
Sometimes, during the implementation of a specific use case, you may want to have some arguments fixed (that is, having a value) or set to a default. For example, you want to convert a number to another number with base 8 or perhaps base 16. The approach best suited to this would be to have a generic function that takes up a parameter base, which is then set to the number as per the requirement.
Hence, instead of having functions like convert_to_octal() or convert_to_hex(), you just have convert_to_base(base = 8) or convert_to_base(base = 16).
A simpler example for optional arguments:
# function f takes 1 mandatory argument and# 2 optional argumentsjulia> function f(x, y=4, z=10) x+y+zendf (generic function with 1 method) ...
Read now
Unlock full access