In Fortran, we know that we can in a module define a global variable (use the private property), so that we can use the subroutines in the module to set or change the values of that variable. See below,
module Mod
integer, parameter :: r8=selected_real_kind(15,9)
real(kind=r8), private, save :: var
contains
subroutine f(x)
real(kind=r8) :: x
var = 2.0_r8*x
end subroutine f
end
As we can see, we can call f(x) and set the var in the module to be 2x.
Now in Julia, it seems like below,
module Mod
global var
function f(x::Float64)
global var = 2.0*x
return nothing
end
I mean, in the function, if var is on the left hand side, do I have to specify the key word 'global' every time?
I also tried to give the global var a type, like
global var::Float64
But it gives me an error
syntax: type declarations on global variables are not yet supported
It seems i can only do either just specify nothing, like just
global var
or give it a value while setting its type,
global var=0.0::Float64
Is there better to just give the global var a type before using it?