# A way to get the current method?

**URL:** <https://discourse.julialang.org/t/a-way-to-get-the-current-method/22619>\
**Category:** General Usage\
**Created:** [April 2, 2019, 12:31am UTC](https://discourse.julialang.org/t/a-way-to-get-the-current-method/22619 "2019-04-02T00:31:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [April 2, 2019, 12:31am UTC](https://discourse.julialang.org/t/a-way-to-get-the-current-method/22619/1 "2019-04-02T00:31:01Z")

</div>

For reflection purposes, I’m curious if there’s a way to get the current method? Something like:

```julia
function f(x)
    get_current_method() # would return the f(x) Method
end

function f(x,y)
    get_current_method() # would return the f(x,y) Method
end

```

Honestly it seems like a long-shot this would exist, but figured I’d ask just in case, or maybe I’ll learn something from someone explaining why this can never exist in Julia 🙂

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 2, 2019, 12:35am UTC](https://discourse.julialang.org/t/a-way-to-get-the-current-method/22619/2 "2019-04-02T00:35:20Z")

</div>

Depending on what you want to do with the result, you might be able to get what you need from the built-in `stacktrace()` function.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [April 2, 2019, 12:39am UTC](https://discourse.julialang.org/t/a-way-to-get-the-current-method/22619/3 "2019-04-02T00:39:54Z")

</div>

Nice, thanks, glad I asked!

```julia
julia> get_current_method() = stacktrace()[2].linfo.def
get_current_method (generic function with 1 method)

julia> function f(x)
           get_current_method()
       end
f (generic function with 1 method)

julia> function f(x,y)
           get_current_method()
       end
f (generic function with 2 methods)

julia> f(1)
f(x) in Main at REPL[2]:2

julia> f(1,2)
f(x, y) in Main at REPL[3]:2

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [April 2, 2019, 12:40am UTC](https://discourse.julialang.org/t/a-way-to-get-the-current-method/22619/4 "2019-04-02T00:40:01Z")

</div>

> <https://github.com/JuliaLang/julia/issues/31515>
>
> Sometimes it would be nice to know what method a macro is called from. One examp…le: https://github.com/timholy/Revise.jl/issues/259
> 
> This would be a huge change because the macro-function would have to go from a signature \`@mac(\_\_source\_\_, \_\_module\_\_, args...)\` to \`@mac(\_\_source\_\_, \_\_module\_\_, \_\_method\_\_, args...)\`. At toplevel I suppose we'd set \`\_\_method\_\_ = nothing\`.

Mostly for debugging only since we don’t have much else you can do on it now.
