I am auto-generating Julia code and wish to construct an Expr for a for statement for which the iteration variable will be available in the enclosing scope (that’s the spec of the source language). For some reason
julia > q = :p
julia> :(for $q = 1:2:3 end)
:(for p = 1:2:3
end)
The first case is surprising, even to me, but it must be due to the fact that outer p is not valid syntax anyway, so outer $ p with $ interpreted as infix operator is the only interpretation that can work:
The outer keyword exists in Julia 1.5 but not in Julia 1.2. So if you want to use it, you need to update your Julia version. To be honest I had not idea this keyword exists but it is in the manual: Scope of Variables · The Julia Language
The manual for 1.2 includes outer in the section on Loop scoping. It is however missing from the list of keywords in the manual for both 1.2 and 1.5. Anyway, I’ll give 1.5 a try.