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

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

</div>

Copied from [Generate functions inside a function from string](https://discourse.julialang.org/t/generate-functions-inside-a-function-from-string/12331)

```julia
function foo()
    return eval(parse("x->x"))
end
foo()(1)  
# ERROR: MethodError: no method matching (::##9#10)(::Int64)
# The applicable method may be too new: 
# running in world age 21870, while current world is 21871.

```

---

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