Looping over variable names inside a function



I’m trying to write what I thought should be a simple loop over local variables names inside a function for debugging purposes. The pattern is very simple:

function myfunction(args...; kwargs...)

  x, y, z = other_function(args...)

  for var in (:x, :y, :z)
    println("size($(string(var))) = ", size(eval(var)))

The for loop fails with an error message saying that x isn’t defined. I presume that’s because eval looks in the global scope. How can I make it look in the local scope? It feels like I should place an @eval somewhere but I tried before println, before for, and before function without success. Sorry if the answer is in the metaprogramming section of the manual; that section is quite opaque for me.



No it’s intentionally impossible. Use a Dict with Symbol keys or a type with multiple fields to achieve something similar.


Ok, thank you!