# Names of anonymous and inlined functions

**URL:** <https://discourse.julialang.org/t/names-of-anonymous-and-inlined-functions/6608>\
**Category:** New to Julia\
**Created:** [October 22, 2017, 1:22pm UTC](https://discourse.julialang.org/t/names-of-anonymous-and-inlined-functions/6608 "2017-10-22T13:22:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![improbable22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/improbable22/32/5464_2.png) [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Post date:** [October 22, 2017, 1:22pm UTC](https://discourse.julialang.org/t/names-of-anonymous-and-inlined-functions/6608/1 "2017-10-22T13:22:56Z")

</div>

I have two questions relating to function names, which don’t affect how anything works just some pretty output.

The first is whether there’s a good way to discover the name of the function which called your function. An attempt like this sometimes gets it right, but sometimes I get “#caller#249” etc, I guess according to which functions got inlined. Is there a better way?

```julia
@noinline function myprint(str...)
    name = string(stacktrace()[2].func)
    println(string(name," says ",str...))
end

```

The second question relates to anonymous functions, and the names of variables which contain them. It’s convenient to generate some functions I need something like this:

```julia
function gen(n)
    (x,y) -> sum((x+n)^y)+n
end

a = gen(11)
b = gen(22)
c(x,y) = sum((x+33)^y) +33

```

These control how some data gets processed. I’d like the name of the function used to appear on the plot of the result. I pass it to a function like this:

```julia
function foo(data, f::Function)
    # do stuff
    myprint("all done now, with ",string(f))
end

foo(44,a) # names function "#1"  
foo(55,c) # correctly uses name "c"

```

Can a function like `foo` see the name “a”? Or can `gen` somehow attach it?

I suppose I can do this but it seems a bit ugly to use:

```julia
function foo(data, fsymb::Symbol)
    f = eval(fsymb)
    # do stuff
    myprint("all done now, with ",string(fsymb))
end

foo(66,:a)

```

---

<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:** [October 22, 2017, 1:37pm UTC](https://discourse.julialang.org/t/names-of-anonymous-and-inlined-functions/6608/2 "2017-10-22T13:37:43Z")

</div>

> [@improbable22](#):
>
> I guess according to which functions got inlined. Is there a better way?

The inconsistency is a bug and will be fixed.

> [@improbable22](#):
>
> the names of variables which contain them

In no case is that significant or accessible.

> [@improbable22](#):
>
> Can a function like foo see the name “a”? Or can gen somehow attach it?

No.

> [@improbable22](#):
>
> function foo(data, fsymb::Symbol)  
> f = eval(fsymb)  
> # do stuff  
> myprint("all done now, with ",string(fsymb))  
> end
> 
> foo(66,:a)

Don’t `eval` it’s wrong, but you can use a macro to capture the expression.

---

<div class="post-metadata">

**Author:** ![improbable22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/improbable22/32/5464_2.png) [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Post date:** [October 22, 2017, 1:41pm UTC](https://discourse.julialang.org/t/names-of-anonymous-and-inlined-functions/6608/3 "2017-10-22T13:41:55Z")

</div>

OK, many thanks!
