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

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:

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

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.

1 Like

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

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:

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

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

3 Likes