This is probably a stupid question but I don’t understand why this doesn’t work, I’m using Julia 1.9.2:
defining
a = [:f1, :(f2::Int)]
when I do
[ifelse(typeof(x) == Expr, x.args, x) for x in a]
I get
ERROR: type Symbol has no field args
Stacktrace:
[1] getproperty
@ .\Base.jl:37 [inlined]
[2] (::var"#55#56")(x::Symbol)
@ Main .\none:0
[3] iterate
@ .\generator.jl:47 [inlined]
[4] collect(itr::Base.Generator{Vector{Any}, var"#55#56"})
@ Base .\array.jl:782
[5] top-level scope
@ REPL[38]:1
why the error refers to a symbol when the if is on the expression? And why it fails? Is this a bug? As a last resource, I also tried to switch x
and x.args
but nothing changed
Strangely this instead works:
julia> [ifelse(typeof(x) == Expr, 1, 0) for x in a]
2-element Vector{Int64}:
0
1