# How to define a function(x) to print the name and value of a variable?

**URL:** https://discourse.julialang.org/t/how-to-define-a-function-x-to-print-the-name-and-value-of-a-variable/3348
**Category:** New to Julia
**Created:** [April 23, 2017, 5:39pm UTC](https://discourse.julialang.org/t/how-to-define-a-function-x-to-print-the-name-and-value-of-a-variable/3348 "2017-04-23T17:39:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)
#### Post date: [April 23, 2017, 5:39pm UTC](https://discourse.julialang.org/t/how-to-define-a-function-x-to-print-the-name-and-value-of-a-variable/3348/1 "2017-04-23T17:39:23Z")

</div>

I would like to replicate the following behavior with a function

`data = [1;2]`  
`macro Name(arg) string(arg) end`  
`print(@Name(data), " <- ", data)`  
`> data <- [1,2]`

`function flow(arg) flow(data)`  
`> data <- [1,2]`

Most likely this should be very simple, but yet I didn’t find an easy way (or otherwise) to get: `data<-[1,2]`

Thank you!

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [April 23, 2017, 5:43pm UTC](https://discourse.julialang.org/t/how-to-define-a-function-x-to-print-the-name-and-value-of-a-variable/3348/2 "2017-04-23T17:43:52Z")

</div>

I think this needs to be done with a macro. A function does not have access to “the name of a variable”. This is a function on the expression, not on the values, so it should be a macro. For the same reason, `@show` is a macro.

Have you considered using `@show` for this?

---

<div class="post-metadata">

### Author: ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)
#### Post date: [April 24, 2017, 1:16pm UTC](https://discourse.julialang.org/t/how-to-define-a-function-x-to-print-the-name-and-value-of-a-variable/3348/3 "2017-04-24T13:16:03Z")

</div>

> [@ChrisRackauckas](#):
>
> I think this needs to be done with a macro.

Thank you for the explanation why it cannot be done with a function
