# Function definition hook?

**URL:** https://discourse.julialang.org/t/function-definition-hook/59709
**Category:** General Usage
**Tags:** question
**Created:** [April 21, 2021, 3:57am UTC](https://discourse.julialang.org/t/function-definition-hook/59709 "2021-04-21T03:57:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [April 21, 2021, 3:57am UTC](https://discourse.julialang.org/t/function-definition-hook/59709/1 "2021-04-21T03:57:16Z")

</div>

Is it possible to hook into function definition? Whenever a new function or method is defined I want to do something with the new function.

---

<div class="post-metadata">

### Author: ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)
#### Post date: [April 21, 2021, 5:44am UTC](https://discourse.julialang.org/t/function-definition-hook/59709/2 "2021-04-21T05:44:22Z")

</div>

If you have an access to the source code than you can just directly edit it. If you do not have such an access, you can use [Cassette.jl](https://github.com/JuliaLabs/Cassette.jl) to introspect and transform function body. I think, that you can’t get an access to the original text representation of the function body though, because it is compiled away.

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [April 21, 2021, 5:54am UTC](https://discourse.julialang.org/t/function-definition-hook/59709/3 "2021-04-21T05:54:22Z")

</div>

I don’t need to change the function body itself, I’m just looking to use the function object. Can I do something like this?

```julia
Base.add_function_definition_hook!(func -> @show(func))

```
