Julia v1.3.1 hangs when running the following call of pickvarnames(:(a + b)):
pickvarnames(ex::Symbol) = ex
function pickvarnames(ex::Expr)
varnames = ()
if ex.head == :call
for arg in ex.args[2:end]
varnames = (varnames..., pickvarnames(arg) )
end
end
return varnames
end
julia> pickvarnames(:a)
:a
julia> pickvarnames(:(a + b) )
Killed: 9
why???
I tried using Debugger.jl, calling @enter pickvarnames(:(a + b)) and there’s no problem stepping thru the whole function… what can I do??? thanks.
Since all outputs are symbols, I would recommend returning a Vector{Symbol}, and for symbols too, eg
pickvarnames(ex::Symbol) = [ex]
function pickvarnames(ex::Expr)
varnames = Symbol[]
if ex.head == :call
for arg in ex.args[2:end]
append!(varnames, pickvarnames(arg))
end
end
varnames
end
is the identication of the exact problem out of the reach of non-core guys (like me)? I mean, using tools like @code_xxx seems not showing the problem also…
I had tried the same things in global scope but had no problems too. In the mean time, when added @show before the said line in the function, interrupting the hanging process can show varnames within if statement. Maybe, I am mistaken about the source of problem but it hangs before showing varnames.