Defining a variable within a function at the module scope?

Hi,

I was wondering how can i define a variable at the module scope within a function or code block.
Is my only option “global” keyword?
or is there function define(MODULE,sym)

Thanks

Why do you need another option, and what is wrong with using global?

1 Like

i am just asking…

You could use eval, as that always operates in global scope, but that is even “worse” than global.

It would be better if you explained what you are trying to accomplish.

You should never define a global variable within a function, only access it. That’s what global is for. In practice, if you want to provide type information to the compiler, you would use a container anyway, so you may not even need that. For example,

module Foo

const v = [1.0]

function change(Δ)
    v[1] += Δ
end

end
1 Like