TreeView.jl icon indicating copy to clipboard operation
TreeView.jl copied to clipboard

View tree of expression stored in variable

Open dpo opened this issue 6 years ago • 6 comments

I'm on Julia 1.0.3, TreeView 0.3.1 in an IJulia notebook:

julia> myexpr = :(1.0 * x[1] + -1.0 * x[2] + -1.0 * x[3])
julia> @tree @eval myexpr
LabelledTree({4, 3} directed simple Int64 graph, Any[:macrocall, Symbol("@eval"), :(#= In[21]:1 =#), :objexpr])

On a side note, it took me a moment to realize that I needed @eval here. If this usage is correct, perhaps there could be an example in the README. This may also be related to #19?!

dpo avatar Feb 20 '19 03:02 dpo

Sorry; brew install pdf2svg.

dpo avatar Feb 20 '19 03:02 dpo

Please feel free to suggest improvements for the README.

dpsanders avatar Feb 20 '19 19:02 dpsanders

I got confused. The @eval trick doesn't work; it displays something else. How does one display an expression stored in a variable? Just call tree_walk(myexpr)?

dpo avatar Feb 20 '19 20:02 dpo

This is currently not enabled via the macro, though it would be a useful addition, so I've reopened the issue and changed the title.

Indeed just calling the function is a good workaround.

dpsanders avatar Feb 20 '19 22:02 dpsanders

Ok, thank you!

dpo avatar Feb 20 '19 23:02 dpo

The syntax could be @tree $myexpr. This requires explicitly handling the relevant $ syntax in the expression parser and escaping the resulting variable.

dpsanders avatar Feb 20 '19 23:02 dpsanders