Variable Keword arguments should be Final

Hello, I am using Julia 1.10.4 and I am confused about the variable keyword arguments place.
According to this from the docs:

The nature of keyword arguments makes it possible to specify the same argument more than once. For example, in the call plot(x, y; options..., width=2) it is possible that the options structure also contains a value for width . In such a case the rightmost occurrence takes precedence; in this example, width is certain to have the value 2 . However, explicitly specifying the same keyword argument multiple times, for example plot(x, y, width=2, width=3) , is not allowed and results in a syntax error.

we can see that the variable kwargs are used before the final position, however when I use them before the final position an error occur ?

function everything(x, k = 1, y...; z..., j = "Hello")
    println(x)
    println(y)
    println(k)
    println(z)
    println(z...)
end

everything(15,16,20,21,22;v1 = 1, v2 =2)

I get the error:

syntax: invalid "..." on non-final keyword argument

The example in the docs is - as you say - a call.
You are however trying this syntax in the definition a function where it is not valid.

4 Likes

In the function definition it has to always be last (basically “collecting the rest”),
but in a function call you can pass down the options (maybe some “collected rest from before” sa keywords. In a call they can be passed down before, because the last occurrence of a keyword wins.
In the concrete example, if the options would contain a width, that would be ignored, since that is set to 2 afterwards.

The same “collect the rest” also holds for the arguments (your y...). I n a function definition this has to be last (before the ;).

2 Likes