# 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:** 26

<div class="post-metadata">

**Author:** ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Post date:** [July 13, 2018, 6:25am UTC](https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331/26 "2018-07-13T06:25:16Z")

</div>

I created a separate thread here summarizing generally what I want:

> [@How do I create a function from an expression](https://discourse.julialang.org/t/how-do-i-create-a-function-from-an-expression/12349):
>
> Suppose I have expr = :(sin(x)+cos(x)) How can I get a function looking like x-\>sin(x)+cos(x) I have tried to write such a macro macro expr2fn(expr, arg) return :($arg -\> $(expr)) end but it does not work julia\> f = @expr2fn expr x (::#63) (generic function with 1 method) julia\> f(1.0) :(sin(x) + cos(x)) Not sure what is happening here.

---

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