MethodError with @

I define a function with multiple parameters, but it throws a MethodError when @. is not the last parameter.
Example:

julia> function f(x, y)
           println(x, y)
       end
f (generic function with 1 method)

julia> x = [1, 2, 3]
3-element Array{Int64,1}:
 1
 2
 3

julia> f(x, x.^2)
[1, 2, 3][1, 4, 9]

julia> f(x, @. x^2)
[1, 2, 3][1, 4, 9]

julia> f(x.^2, x)
[1, 4, 9][1, 2, 3]

julia> f(@. x^2, x)
ERROR: MethodError: no method matching f(::Tuple{Array{Int64,1},Array{Int64,1}})
Closest candidates are:
  f(::Any, ::Any) at REPL[1]:1
Stacktrace:
 [1] top-level scope at REPL[6]:1

Is this a bug?

f(@.(x^2), x)

I agree it can be improved

1 Like

Thank you for your reply.
It seems that parameters after @. are regarded as a tuple.
Modified:

julia> f(@.(x^2), x)
[1, 4, 9][1, 2, 3]

julia> f((@. x^2), x)
[1, 4, 9][1, 2, 3]

I actually have an open issue about this: https://github.com/JuliaLang/julia/issues/36547, it looks like it probably can’t change until 2.0, but if someone made a PR and rand PackageEval and nothing broke, it could be up for consideration before that.

2 Likes