Evaluate expression with variables from a dictionary

This is one way to do it.

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> interpolate_from_dict(f1, data)
:(1 + 2)

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