# Enable interpolation when doing Meta.parse()

**URL:** https://discourse.julialang.org/t/enable-interpolation-when-doing-meta-parse/29906
**Category:** General Usage
**Tags:** metaprogramming
**Created:** [October 14, 2019, 3:28pm UTC](https://discourse.julialang.org/t/enable-interpolation-when-doing-meta-parse/29906 "2019-10-14T15:28:01Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![AlwaysPS](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@AlwaysPS](https://discourse.julialang.org/u/AlwaysPS)
#### Post date: [October 14, 2019, 3:28pm UTC](https://discourse.julialang.org/t/enable-interpolation-when-doing-meta-parse/29906/1 "2019-10-14T15:28:01Z")

</div>

I’m trying to build a toy program using the nonlinear facility of JuMP. The general structure looks like this:

```julia
function solve(constraint::String)
    model = Model()
    vars = @variable(model, [1:10], base_name="x")
    …
    cons_expr = Meta.parse(constraint)
    add_NL_constraint(model, cons_expr)
end

```

The problem here is: function `add_NL_constraint` accepts an `Expr` of _JuMP variables_, which are created in `solve`. Therefore, directly parsing the input string (such as the above code) will not work.

To be more specific, that means:

```julia
add_NL_constraint(model, :($(vars[1])==0)) # OK
add_NL_constraint(model, Meta.parse("vars[1]==0")) # not OK, not JuMP variables
add_NL_constraint(model, Meta.parse("\$(vars[1])==0")) # not OK, does not trigger interpolation

```

Is there a way to enable interpolation in `Meta.parse()`, so that the last approach can work?
