# Is there something equivalent to deparse(substitute(x)) in Julia?

**URL:** <https://discourse.julialang.org/t/is-there-something-equivalent-to-deparse-substitute-x-in-julia/47666>\
**Category:** New to Julia\
**Created:** [October 2, 2020, 8:58pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-deparse-substitute-x-in-julia/47666 "2020-10-02T20:58:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![julianjohs](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@julianjohs](https://discourse.julialang.org/u/julianjohs)\
**Post date:** [October 2, 2020, 8:58pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-deparse-substitute-x-in-julia/47666/1 "2020-10-02T20:58:51Z")

</div>

Dear all,

coming from R, I used to use deparse(substitute(x)) to get the name of an object x as a string. Is there anything similar in Julia?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [October 2, 2020, 10:39pm UTC](https://discourse.julialang.org/t/is-there-something-equivalent-to-deparse-substitute-x-in-julia/47666/2 "2020-10-02T22:39:05Z")

</div>

Hi julianjohs, welcome to Julia Discourse.

The short answer is **no**.

In Julia, there is no concept of an object having _one_ name. It may have multiple bindings (i.e., ways to refer to it) in multiple scopes. It may be called `x` in your global scope, and passed to a method in which (inside the method) it is called `y`, for example. All these names are external to the object and the object itself is not aware of any of them.

The long answer is _it depends_.

Using macros, Julia allows you to capture an expression. For example,

```julia
julia> x = 10
10

julia> @show x
x = 10
10

julia> @show x + 10
x + 10 = 20
20

```

But this is, probably, much more limited than what you want. In Julia, macros cannot do anything the programmer could not do by hand, with a little more effort and repetition of code. So, they only serve to automate code patterns. In your case, it seems like you will need to write code that pass an object and a name for it to be used, macros can help you to do that, but this does not change the fact you (yourself, not the language) is making the effort of passing a String together with an arbitrary object.

Example on how to achieve it:

```julia
struct NamedObject{T}
    name :: String
    object :: T
end

macro wrap_name(expression)
    quote
        NamedObject(string($(Meta.quot(expression))), $expression)
    end
end

@wrap_name(log10(1000))

```

returns

```julia
NamedObject{Float64}("log10(1000)", 3.0)

```
