# How to get the code behind an anonymous function represented as Symbol("##...")

**URL:** https://discourse.julialang.org/t/how-to-get-the-code-behind-an-anonymous-function-represented-as-symbol/27279
**Category:** General Usage
**Created:** [August 7, 2019, 5:57pm UTC](https://discourse.julialang.org/t/how-to-get-the-code-behind-an-anonymous-function-represented-as-symbol/27279 "2019-08-07T17:57:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)
#### Post date: [August 7, 2019, 5:57pm UTC](https://discourse.julialang.org/t/how-to-get-the-code-behind-an-anonymous-function-represented-as-symbol/27279/1 "2019-08-07T17:57:27Z")

</div>

I’m extensively using code like this:

```julia
route("/") do
  "Hello World"
end

```

which gets custom printed as:

```julia
[GET] / => getfield(Main, Symbol("##3#4"))()

```

It would be a lot more usable and informative if I could actually retrieve the code behind `Symbol("##3#4"))`. Is this possible? Thanks!

---

<div class="post-metadata">

### Author: ![jmert](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmert/32/3161_2.png) [@jmert](https://discourse.julialang.org/u/jmert)
#### Post date: [August 7, 2019, 7:01pm UTC](https://discourse.julialang.org/t/how-to-get-the-code-behind-an-anonymous-function-represented-as-symbol/27279/2 "2019-08-07T19:01:58Z")

</div>

Is this what you’re thinking?

```julia
julia> f = x -> 2x
#7 (generic function with 1 method)

julia> m = first(methods(f))
(::getfield(Main, Symbol("##7#8")))(x) in Main at REPL[1]:1

julia> using CodeTracking

julia> whereis(m)[1]
"REPL[1]"

julia> CodeTracking.src_from_file_or_REPL(whereis(m)[1])
"f = x -> 2x"

```

Edit: `CodeTracking` basically has this in its README. Using just exported functions, it can instead be written,

```julia
julia> definition(String, @which f(1.0))[1]
"f = x -> 2"

```

---

<div class="post-metadata">

### Author: ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)
#### Post date: [August 8, 2019, 8:03am UTC](https://discourse.julialang.org/t/how-to-get-the-code-behind-an-anonymous-function-represented-as-symbol/27279/3 "2019-08-08T08:03:54Z")

</div>

That’s pretty cool, thank you!
