At various points in my exploration of Julia code, I find ... being used. For example, in help for symbol ?Symbol
Symbol(x...) -> Symbol
And, currently, I’m using the following code that includes ... to create a data frame from an array (using the first row as the column titles).
DataFrame_wTitles = DataFrame([[anArray[2:end,i]...] for i in 1:size(anArray,2)], Symbol.(anArray[1,:]))
However, it’s difficult to find documentation on ... or “three dots”, or “dots” . . . Broadcasting uses dot notation. It’s short and sweet notation, but I wonder how ... is officially referred to and does it have several meanings.
Others have answered already but I thought it might be useful to add the ? answer:
help?> ...
search: ...
...
The "splat" operator, ..., represents a sequence of arguments. ... can be used in function definitions, to indicate
that the function accepts an arbitrary number of arguments. ... can also be used to apply a function to a sequence
of arguments.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> add(xs...) = reduce(+, xs)
add (generic function with 1 method)
julia> add(1, 2, 3, 4, 5)
15
julia> add([1, 2, 3]...)
6
julia> add(7, 1:100..., 1000:1100...)
111107
So whenever you don’t know what a certain operator/symbol/whatever does, you can try the built-in ? functionality.
This is excellent advice, though one thing it falls down on us the ternary operator. Took me forever to figure out how to google “question mark and colon syntax”…
help?> ?
search: ? ?:
a ? b : c
Short form for conditionals; read "if a, evaluate b otherwise evaluate c". Also known as the ternary operator (https://en.wikipedia.org/wiki/%3F:).
This syntax is equivalent to if a; b else c end, but is often used to emphasize the value b-or-c which is being used as part of a larger expression, rather than the side effects that evaluating b or c may have.
See the manual section on control flow for more details.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> x = 1; y = 2;
julia> println(x > y ? "x is larger" : "y is larger")
y is larger
LOL. Julia user since 0.5.something. Just now finding out ? gives you a help repl.
however, when I tried to do help on ?: as per @nilshg 's example this is what happens…
help?> ?
search:
Welcome to Julia 1.4.2. The full manual is available at
https://docs.julialang.org/
as well as many great tutorials and learning resources:
https://julialang.org/learning/
For help on a specific function or macro, type ? followed by its name, e.g.
?cos, or ?@time, and press enter. Type ; to enter shell mode, ] to enter
package mode.
julia>
typing ? at the help?> prompt drops me back to the repl where as in his example it seems to drop you into a search prompt ??