# Generate functions inside a function from string

**URL:** <https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331>\
**Category:** Performance\
**Tags:** question\
**Created:** [July 12, 2018, 1:15pm UTC](https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331 "2018-07-12T13:15:13Z")\
**Posts on this page:** 1\
**Showing post:** 37

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [July 13, 2018, 4:48pm UTC](https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331/37 "2018-07-13T16:48:59Z")

</div>

As discussed in the other thread, in the `SyntaxTree` package there is now an updated `genfun` and `@genfun` for creating functions, and it now does not require `Base.invokelatest`, so is faster

> [@How do I create a function from an expression](https://discourse.julialang.org/t/how-do-i-create-a-function-from-an-expression/12349/21):
>
> Actually, I have just figured out to do this macro without Base.invokelatest and updated SyntaxTree : julia\> using SyntaxTree, BenchmarkTools julia\> g = genfun(:(-(cos(x))),[:x]) (::#3) (generic function with 1 method) julia\> @btime $g(1.0) 40.790 ns (0 allocations: 0 bytes) -0.5403023058681398 julia\> f = @genfun -cos(x) [x] (::#3) (generic function with 1 method) julia\> @btime $f(1.0) 40.801 ns (0 allocations: 0 bytes) -0.5403023058681398 Now the evaluation is much faster because it i…

---

_[View the full topic](https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331)._
