julia> bar(a,b,x...) = (a,b,x)
bar (generic function with 1 method)
julia> bar(1,2)
(1,2,())
Is () a zero-argument anonymous function that takes in varargs, making zero really mean any-argument anonymous function? If yes, then to me, the name zero-argument name just doesn’t fully capture/represent what it is. Anyone else feel this way?
If the zero-argument name changed to any-argument, I wouldn’t see the need to also use the name varargs. Or if zero changed to var-arguments, wouldn’t see the need to use zero and varargs.
The () in ()->3 is not a name. It is also akin to an empty tuple. Tuples represent the arguments of functions; an empty tuple means that the function takes no arguments.
f() = 3 and const f = ()->3 are basically defining the same thing.
() is just parenthesis. In general it’s used when the syntax can otherwise be ambiguous.
In most cases it’s optional. You can write x->x instead of (x)->x, x, y instead of (x, y). Zero element tuples and zero argument functions needs the () since it’ll be hard to represent otherwise.
Yup, that exact Doc section led me here. Your previous comment about representing a zero element tuple drove the point home. It must be represented, even though there’s nothing you can do with it. Thanks.
Because one element tuples need the additional comma to distinguish them from regular parentheses. Two element tuples are not ambiguous so the extra comma is not required. For example:
julia> 1 # just an integer
1
julia> (1) # also just an integer
1
julia> (1,) # one element tuple
(1,)
julia> (1, 2) # two element tuple
(1,2)
julia> (1, 2,) # also a two element tuple
(1,2)
Nothing is quoted. You are just passing more than one argument for the vararg part. It’s the same as bar(1, 2, 3, 4) so x === (3, 4) and (a, b, x) === (1, 2, (3, 4)).
Why is splice quoted: I pasted the blockquote directly from the Julia Doc. Does splice here differ from splice in the original sense?
Despite the definition of bar(a,b,x...) = (a,b,x), when x = (2,3,4), why does calling bar(1,x...) => (1,2,(3,4)) and not => (1,(2,3,4))? Is the function definition assigning b = 2, first iterable of the collection x? If yes, what’s the point of that?
On the flip side, it is often handy to “splice” the values contained
instead of On the flip side, it is often handy to splice the values contained?
I don’t follow. The explanation I came up with is that bar(1,x...) => (1,2,(3,4)) where x = (2,3,4) is so because bar(a,b,x...) = (a,b,x) was defined as such, where b must be assigned to something. Is that a correct interpretation?