How can I do the transformation of :Int to the correct concrete type symbol in a macro?
what do you mean by correct concrete type symbol?
Depending on platform get :Int64 or :Int32 instead of :Int
there is no correct symbol though.
julia> let Int32 = Base.Int64, Int64 = Base.Int32, Int = Float64
typeof((Int32(1), Int64(2), Int(3)))
end
Tuple{Int64, Int32, Float64}
If you have the type itself, you could just do Symbol(T)
to get it's symbol and that'll have the 64
or 32
in it.
julia> Symbol(Int)
:Int64
That works! Thank you. For future reference:
julia> macro t(e)
:(Tuple{$(Symbol(e))})
end
@t (macro with 1 method)
julia> @t Int
Tuple{Int64}
@Simon Christ I don't think that macro does what you think it does. The Symbol
constructor isn't doing anything:
julia> macro t2(e)
:(Tuple{$e})
end
@t (macro with 1 method)
julia> @t Int
Tuple{Int64}
On 64bit computers, Int === Int64
, whereas on 32 bit computers, Int === Int32
. E.g. on my machine:
julia> Int
Int64
Hmm.. seems my confusion was more about how to splat correctly:
julia> macro t(e)
:(Tuple{$(e.args...)}) |> esc
end
@t (macro with 1 method)
julia> @t [Int, Any]
Tuple{Int64,Any}
julia> macro t(e)
:(Tuple{$(e.args)...}) |> esc
end
@t (macro with 1 method)
julia> @t [Int, Any]
Tuple{:Int,:Any}
Last updated: Dec 28 2024 at 04:38 UTC