November 2017
Beginner
316 pages
6h 40m
English
Varargs stands for variable arguments. These come in handy when we are not sure about the total number of arguments to be passed to a function in advance. Hence, we want to have an arbitrary number of arguments.
The way we achieve this in Julia is by using three dots or .... Let's use an example to explain this further:
julia> function letsplay(x,y...) println(x) println(y) endletsplay (generic function with 1 method)julia> letsplay("cricket","hockey","tennis")cricket("hockey","tennis")
Here, we have defined a letsplay() function that prints the names of the games we pass. Here, Julia interprets these arguments as positional and maps them accordingly.
The first argument, x, is mapped to cricket on a function call and is displayed ...
Read now
Unlock full access