# Is this a good way to export all variables inside of a function?

**URL:** <https://discourse.julialang.org/t/is-this-a-good-way-to-export-all-variables-inside-of-a-function/73699>\
**Category:** General Usage\
**Created:** [December 28, 2021, 11:24am UTC](https://discourse.julialang.org/t/is-this-a-good-way-to-export-all-variables-inside-of-a-function/73699 "2021-12-28T11:24:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [December 28, 2021, 11:24am UTC](https://discourse.julialang.org/t/is-this-a-good-way-to-export-all-variables-inside-of-a-function/73699/1 "2021-12-28T11:24:39Z")

</div>

Hello!

Not a question per se, more looking for some feedback I suppose.

So by googling a bit, I came around and saw that it is possible to call a macro called Base.@locals, which if you use it inside of a function, you can make it return all variables inside of the function as such:

```julia
return Base.@locals

```

I have a need for this right now (or atleast I think I do), is there something I should be aware about when using this?

Kind regards

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 28, 2021, 1:16pm UTC](https://discourse.julialang.org/t/is-this-a-good-way-to-export-all-variables-inside-of-a-function/73699/2 "2021-12-28T13:16:17Z")

</div>

> [@Ahmed\_Salih](#):
>
> I have a need for this right now (or atleast I think I do), is there something I should be aware about when using this?

I think it is unlikely that someone needs that, except for some temporary debugging purpose perhaps. Probably what is needed is a better data organization, using structs, dicts, tuples, etc.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 28, 2021, 1:20pm UTC](https://discourse.julialang.org/t/is-this-a-good-way-to-export-all-variables-inside-of-a-function/73699/3 "2021-12-28T13:20:23Z")

</div>

you don’t need this. what are you trying to do?

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [December 28, 2021, 2:06pm UTC](https://discourse.julialang.org/t/is-this-a-good-way-to-export-all-variables-inside-of-a-function/73699/4 "2021-12-28T14:06:05Z")

</div>

Thanks both of you @lmiq and @Oscar_Smith

I am working with EzXML.jl and trying to work easier with the data. Currently I am making the XML in such a way that I am generating each node and naming it to a variable which makes sense. Then by using the export function as shown in my first post, I can get a dict out of the variables to work easierly with automatically.

Perhaps I should look a bit more into mutable structs again, but I have not found something which allows me to write something akin to:

```julia
XMLDoc.Tag1.Subtag2

```

Which is properly what I should try to see if I can get up and working. For now Base.@locals is just used as an easy workaround, since it produces it in a dict format that I can work with, compared to not having it work before hand.

Kind regards

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 28, 2021, 2:25pm UTC](https://discourse.julialang.org/t/is-this-a-good-way-to-export-all-variables-inside-of-a-function/73699/5 "2021-12-28T14:25:28Z")

</div>

Hard to tell without a more concrete example, but why don’t you create such a dict inside the function and return it?
