Opening up an Expr for easier manipulation

in the relm of metaprogramming: Given an arbitrary well-formed Expr that contains zero or more symbols, to replace each symbol by a value chosen as its referent (given in an available Dict) one assigns into the appropriate Expr.args[n].&tc. Getting there may be half the fun for some … I am wondering if there is a nifty way to open up an Expr so each of its constituent Symbols is available by immediate lookup opened = openup(expr); keys(opened) are the Symbols, values(opened) are the paths into the expr that hold and that may replace the associated key symbol with some other typed value, I realize there needs to be a way to handle symbols that occur more than once – the values may be tuples.
And for this to be helpful, a corresponding unopen( opened ) algorithm is needed.

Is this available?

It is not very clear what you want to do, perhaps an example would help. But if I understand correctly, you want an expression walker, see

1 Like

You might be interested in functions subs() and rewrite() from Espresso.jl.

3 Likes

thank you for the link … that appears to be less work for me