# Interpolate expression into macro

**URL:** <https://discourse.julialang.org/t/interpolate-expression-into-macro/24204>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [May 14, 2019, 11:26am UTC](https://discourse.julialang.org/t/interpolate-expression-into-macro/24204 "2019-05-14T11:26:29Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 14, 2019, 11:47am UTC](https://discourse.julialang.org/t/interpolate-expression-into-macro/24204/4 "2019-05-14T11:47:50Z")

</div>

Some more background

In the real application, the generated expressions are accessing deeply nested fields in an object. I can either try to interpolate these expressions into a bigger expression, or turn them into functions that update the fields of interest in-place. The function approach works well, but I have to divide it into two so that the world age have time to update 😕

These are my real-world expressions, that are constructed during runtime

```julia
set1expr = quote
    vecpartind2vec!((P2.matrix[1]).num.a, (P.matrix[1]).num.a, partind)
    vecpartind2vec!((P2.matrix[1]).den.a, (P.matrix[1]).den.a, partind)
end
set2expr = quote
    setindex!.((Pres.matrix[1]).num.a, (P2res.matrix[1]).num.a, partind)
    setindex!.((Pres.matrix[1]).den.a, (P2res.matrix[1]).den.a, partind)
end

```

If I make them into functions by

```julia
@eval set1fun = (P,P2,partind)-> $set1expr
@eval set2fun = (Pres,P2res,partind)-> $set2expr

```

I may not use the functions until the world age is updated

---

_[View the full topic](https://discourse.julialang.org/t/interpolate-expression-into-macro/24204)._
