January 2020
Intermediate to advanced
532 pages
13h 31m
English
Slurping is very useful in its own right, but the triple-dot notation actually has a second usage. At the call site, when a variable is followed by three periods, the variable will be automatically assigned as multiple function arguments. This feature is known as splatting. In fact, this mechanism is very similar to slurping, except that it is doing the opposite action. We will take a look at an example.
Let's say that we have written a function to arrange a couple of spaceships in a specific formation:
# Special arrangement before attacksfunction triangular_formation!(s1::Widget, s2::Widget, s3::Widget) x_offset = 30 y_offset = 50 s2.position.x = s1.position.x - x_offset s3.position.x = s1.position.x + x_offset s2.position.y ...
Read now
Unlock full access