# Looping over variable names inside a function

**URL:** https://discourse.julialang.org/t/looping-over-variable-names-inside-a-function/2629
**Category:** General Usage
**Tags:** question, faq
**Created:** [March 13, 2017, 2:17am UTC](https://discourse.julialang.org/t/looping-over-variable-names-inside-a-function/2629 "2017-03-13T02:17:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)
#### Post date: [March 13, 2017, 2:17am UTC](https://discourse.julialang.org/t/looping-over-variable-names-inside-a-function/2629/1 "2017-03-13T02:17:56Z")

</div>

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:

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

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

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

```

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.

Thanks.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [March 13, 2017, 3:32am UTC](https://discourse.julialang.org/t/looping-over-variable-names-inside-a-function/2629/2 "2017-03-13T03:32:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)
#### Post date: [March 13, 2017, 5:52am UTC](https://discourse.julialang.org/t/looping-over-variable-names-inside-a-function/2629/3 "2017-03-13T05:52:31Z")

</div>

Ok, thank you!
