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

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!

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?

2 Likes

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