Slurping on non-final argument

why can i define this function?

julia> f(y,x...)=+(x...).*y
f (generic function with 1 method)

and can’t I define this other one?

julia> f1(x...,y)=+(x...).*y
ERROR: syntax: invalid "..." on non-final 

Couldn’t we gnisrap the arguments in reverse order?

I guess there are many possible side effects to avoid but I am not able to imagine.

See this thread: Optional positional arguments must occur at end - #13 by Jean_Michel

This seems to be about slurping, not about optional arguments.

Here’s a PR that addresses this: allow slurping in any position by simeonschaub · Pull Request #42902 · JuliaLang/julia · GitHub
Not sure when/if it will land.

But currently, this is not allowed.

3 Likes

Note that the PR doesn’t address method dispatch as the OP asked for. That would require changes to the type system to actually be able to represent signatures like this.

3 Likes