# Evaluate expression with variables from a dictionary

**URL:** <https://discourse.julialang.org/t/evaluate-expression-with-variables-from-a-dictionary/30047>\
**Category:** General Usage\
**Created:** [October 18, 2019, 8:49am UTC](https://discourse.julialang.org/t/evaluate-expression-with-variables-from-a-dictionary/30047 "2019-10-18T08:49:20Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 18, 2019, 9:51am UTC](https://discourse.julialang.org/t/evaluate-expression-with-variables-from-a-dictionary/30047/2 "2019-10-18T09:51:36Z")

</div>

This is one way to do it.

```julia
interpolate_from_dict(ex::Expr, dict) = Expr(ex.head, interpolate_from_dict.(ex.args, Ref(dict))...)
interpolate_from_dict(ex::Symbol, dict) = get(dict, ex, ex)
interpolate_from_dict(ex::Any, dict) = ex

```

Then you have

```julia
julia> interpolate_from_dict(f1, data)
:(1 + 2)

julia> eval(interpolate_from_dict(f1, data))
3

```

---

_[View the full topic](https://discourse.julialang.org/t/evaluate-expression-with-variables-from-a-dictionary/30047)._
