# Opening up an Expr for easier manipulation

**URL:** <https://discourse.julialang.org/t/opening-up-an-expr-for-easier-manipulation/4747>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [July 9, 2017, 6:07am UTC](https://discourse.julialang.org/t/opening-up-an-expr-for-easier-manipulation/4747 "2017-07-09T06:07:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [July 9, 2017, 6:07am UTC](https://discourse.julialang.org/t/opening-up-an-expr-for-easier-manipulation/4747/1 "2017-07-09T06:07:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 9, 2017, 6:34am UTC](https://discourse.julialang.org/t/opening-up-an-expr-for-easier-manipulation/4747/2 "2017-07-09T06:34:44Z")

</div>

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

> **[GitHub - FluxML/MacroTools.jl: MacroTools provides a library of tools for...](https://github.com/FluxML/MacroTools.jl)**
>
> MacroTools provides a library of tools for working with Julia code and expressions. - GitHub - FluxML/MacroTools.jl: MacroTools provides a library of tools for working with Julia code and expressions.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [July 9, 2017, 10:32am UTC](https://discourse.julialang.org/t/opening-up-an-expr-for-easier-manipulation/4747/3 "2017-07-09T10:32:42Z")

</div>

> [@JeffreySarnoff](#):
>
> 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]

You might be interested in functions `subs()` and `rewrite()` from [Espresso.jl](https://github.com/dfdx/Espresso.jl).

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [July 9, 2017, 1:15pm UTC](https://discourse.julialang.org/t/opening-up-an-expr-for-easier-manipulation/4747/4 "2017-07-09T13:15:09Z")

</div>

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