# Source code of a function

**URL:** <https://discourse.julialang.org/t/source-code-of-a-function/4499>\
**Category:** General Usage\
**Created:** [June 27, 2017, 5:37pm UTC](https://discourse.julialang.org/t/source-code-of-a-function/4499 "2017-06-27T17:37:20Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![cscherrer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cscherrer/32/7631_2.png) [@cscherrer](https://discourse.julialang.org/u/cscherrer)\
**Post date:** [March 3, 2022, 6:40pm UTC](https://discourse.julialang.org/t/source-code-of-a-function/4499/21 "2022-03-03T18:40:10Z")

</div>

> [@dfdx](#):
>
> The tape can then be transformed and recompiled back to a normal function, so interpretation only happens once.

That’s really interesting. It seems like this with your `Loop` construct could be great for probabilistic programming. It would probably take some extension though. In PPL, for any loop that includes sampling, we’d need (or prefer anyway, I think) to be able to pick up at an arbitrary iteration. This could be something like a sequence of loop states stored as a StructArray.

> [@dfdx](#):
>
> IIUC, `invokelatest(f, args...)` tells Julia not to link to a specific version of `f()` during compilation, but instead go to the method table and get the latest version during runtime. Basically, it’s just a dynamic dispatch, and if you call it only once for the top-level function, its cost is relatively small.

That’s fine for some applications. But for me, for example `rand` needs to build code to sample from a model. This is usually in an inner loop, so it’s important that it only be built once for each type-distinct set of arguments. I think there are lots of other subtleties beyond this. Basically things got a lot better when I started avoiding `eval` when possible.

[Previous page](https://discourse.julialang.org/t/source-code-of-a-function/4499.md?page=1)
