Use of constant types

I am struggling with the issue of changing the type of a global variable.
I keep a set of functions I am working on in a file “global_functions.jl”, which I include in my main program. I then give it a shortcut in the global space, called GF. global_functions.jl has a module defined with the name “globalFunctions_mod”:

GF = globalFunctions_mod

This is equivalent (more or less) to the python construct

import globalFunctions_mod as GF

As I read more, I decided to make GF into a const variable:

const GF = globlFunctions_mod

and continue working on my program. But I get the error:

This makes programming difficult since it is not possible to remove a variable once it is defined. So my question is: how do I change a variable from non-const to const without recompiling my entire program, which seems rather inefficient. I love Julia so far, but there are some quirks of the language that I am having a serious problem embracing. If it is not possible to solve this problem (I probably just do not know how), I would like to understand better the rationale that prevents this type of transformation.

Are you using Revise.jl? That is a must-have.


Yes, once you have enough code to define a module, you should put it in a package, use Revise to update it, and import/using instead of include to access it. Then you won’t have any problems.

Doing a package isn’t hard, and it doesn’t have to be public. You can either

  • Use PkgTemplate.jl
  • Create a folder in .julia/dev/YourPackage, with YourPackage/src/YourPackage.jl containing the source code
  • Create that folder elsewhere, but make sure its parent is in the LOAD_PATH

Then you can using YourPackage. Maybe you’ll have to ] dev YourPackage first.