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


#1

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!


#2

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?


#3

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