I'm trying to build a function that will output an expression to be assigned to a new in-memory function. I might be misinterpreting the capability of metaprogramming but, I'm trying to build a function that generates a math series and assigns it to a function such as:

[![enter image description here](https://i.stack.imgur.com/omZfH.gif)](https://i.stack.imgur.com/omZfH.gif)

main.jl

```
function series(iter)
    S = ""
    for i in 1:iter
        a = "x^$i + "
        S = S*a
    end
    return chop(S, tail=3)
end

```

So, this will build the pattern and I'm temporarily working with it in the repl:

```
julia> a = Meta.parse(series(4))
:(x ^ 1 + x ^ 2 + x ^ 3 + x ^ 4)

julia> f =eval(Meta.parse(series(4)))
120

julia> f(x) =eval(Meta.parse(series(4)))
ERROR: cannot define function f; it already has a value

```

Obviously eval isn't what I'm looking for in this case but, is there another function I can use? Or, is this just not a viable way to accomplish the task in Julia?