# What is the right way to construct and then run a Julia function programmatically?

**URL:** https://discourse.julialang.org/t/what-is-the-right-way-to-construct-and-then-run-a-julia-function-programmatically/25845
**Category:** General Usage
**Tags:** macros
**Created:** [June 29, 2019, 6:51pm UTC](https://discourse.julialang.org/t/what-is-the-right-way-to-construct-and-then-run-a-julia-function-programmatically/25845 "2019-06-29T18:51:30Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [June 29, 2019, 7:05pm UTC](https://discourse.julialang.org/t/what-is-the-right-way-to-construct-and-then-run-a-julia-function-programmatically/25845/2 "2019-06-29T19:05:41Z")

</div>

Here are some potentially useful links:

> [@World Age Problem Explanation](https://discourse.julialang.org/t/world-age-problem-explanation/9714/4):
>
> The reason for worlds is because of optimizations. If functions can be defined (and redefined) at arbitrary points (and instantly take effect), then that would limit the possible optimizations that can be made. Therefore, new functions are only made visible to the system (become usable) after hitting toplevel. If you try to call a new function before this, then you get a world error. In some cases (like if you are writing a REPL), you do actually want to call your newly defined function without…

> [@"running in world age X, while current world is Y" errors](https://discourse.julialang.org/t/running-in-world-age-x-while-current-world-is-y-errors/5871/2):
>
> Here’s my understanding: In version 0.6, Julia now keeps track of all the callers of a given function (called backedges) so it can go back and invalidate the previous code with any updated methods. This invalidation can only happen at “safe” points within the process — you cannot trash a piece of currently running code and expect everything to go well. You cannot even go back and update a function pointer since the old method be inlined or the new one might change the inferred optimizations. …

---

_[View the full topic](https://discourse.julialang.org/t/what-is-the-right-way-to-construct-and-then-run-a-julia-function-programmatically/25845)._
