# How do I create a function from an expression

**URL:** <https://discourse.julialang.org/t/how-do-i-create-a-function-from-an-expression/12349>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 13, 2018, 4:38am UTC](https://discourse.julialang.org/t/how-do-i-create-a-function-from-an-expression/12349 "2018-07-13T04:38:40Z")\
**Posts on this page:** 1\
**Showing post:** 15

<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, 9:34am UTC](https://discourse.julialang.org/t/how-do-i-create-a-function-from-an-expression/12349/15 "2018-07-13T09:34:26Z")

</div>

Please see the post for intention (I am her colleague):

> [@Generate functions inside a function from string](https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331/10):
>
> Well, I am working with SymPy. I would like to build a symbolic matrix and then numerically calculate it. However I found SymPy cannot do the calculation fast enough, e.g. using SymPy @vars x expr=integrate(sin(x)) f=eval(parse("x-\>$(repr(expr))")) g=lambdify(expr,[x]) @time subs(expr,x=\>1.0) @time f(1.0) @time g(1.0) # timing: # 0.000365 seconds (80 allocations: 2.453 KiB) # 0.000003 seconds (5 allocations: 176 bytes) # 0.000016 seconds (9 allocations: 240 bytes) I found eval is the fast…

I am starting a new thread because I think `eval` is not the way out since it’s too restrictive to support local scope.

---

_[View the full topic](https://discourse.julialang.org/t/how-do-i-create-a-function-from-an-expression/12349)._
