JuliaSymbolics/Metatheory.jl

Extracting an `Expr` from `ENodeTerm`

jakevossen5 opened this issue ยท 6 comments

This might be a question for TermInterface.jl, but figured I would ask here because I am dealing with ENodeTerm. As the title suggests, I want to get an Expr type out from a ENodeTerm. I can print the ENodeTerm and get something like nENode{Expr}(var"46โ‚‘" + var"58โ‚‘"). If I just had the second part inside the parens, I could use capture stdout and use Meta.parse to get what I want, but doesn't seem very elegant. Am I missing something obvious?

have you seen extract!? extracts expressions from e-graphs.
if instead you want to do the atomic operation of converting a single e-node to expr, you may do similarterm. Note that similarterm will change soon when #101 is merged.

Ah, similarterm seems to be doing what I need. It am using this: similarterm(Expr, n.operation, map(i -> Symbol(i, "โ‚‘"), n.args)), and it works in most cases of simple operations, but it is getting messed up on something like an if like this: if(var"38โ‚‘", var"45โ‚‘"). My guess is the only way to fix this is to hardcode the case of if, for, etc?

Ah, similarterm seems to be doing what I need. It am using this: similarterm(Expr, n.operation, map(i -> Symbol(i, "โ‚‘"), n.args)), and it works in most cases of simple operations, but it is getting messed up on something like an if like this: if(var"38โ‚‘", var"45โ‚‘"). My guess is the only way to fix this is to hardcode the case of if, for, etc?

similarterm(::Type{T}, ... will be removed. It will only be similarterm(::T, ....
I suggest you to use similarterm(Expr(:call, :blablasomething), n.operation, etc....

Ah, similarterm seems to be doing what I need. It am using this: similarterm(Expr, n.operation, map(i -> Symbol(i, "โ‚‘"), n.args)), and it works in most cases of simple operations, but it is getting messed up on something like an if like this: if(var"38โ‚‘", var"45โ‚‘"). My guess is the only way to fix this is to hardcode the case of if, for, etc?

Also, you should pass the exprhead=exprhead(n) keyword argument to similarterm. Because otherwise, it defaults to :call.
For if, for etc... it wil automatically build the correct expression

Can close?

Yep - thank you!