Brodcasting operator not defined in a macro

The broadcasted division (./) works as it should in functions:

function foo()
    [1 2 3] ./ [4 5 6]
end
julia> foo()
1×3 Array{Float64,2}:
 0.25  0.4  0.5

… but not in macros:

macro foo()
    quote
        [1 2 3] ./ [4 5 6]
    end
end
julia> @foo
ERROR: UndefVarError: ./ not defined
Stacktrace:
 [1] top-level scope at REPL[20]:3

BTW, the same is true of all basic broadcasted operations that I tested (.+, .- and .*). This problem is relatively easily worked around:

macro foo2()
    quote
        (/).([1 2 3], [4 5 6])
    end
end
julia> @foo2
1×3 Array{Float64,2}:
 0.25  0.4  0.5

but am I missing something? Should I report this as an issue ?

Another workaround:

macro foo()
    quote
        @. [1 2 3] / [4 5 6]
    end
end

Cf. this issue:
https://github.com/JuliaLang/julia/issues/28992

3 Likes