Does a script (as opposed to a module or function) introduce any scope, global or local ?
If used with include("myscript") I understood that no new scope is introduced as per Essentials · The Julia Language
And neither in Repl or Jupiter notebook, I believe ?
What about with julia myscript.jl ? I guess Julia creates a new global scope in which myscript.jl is run?
(related) Is it possible to use include("myscript") inside of a function or other constructs, or should it be only at top-level in a module/ Repl?
(I can guess the answers to all these, but I’m not 100% certain, and maybe other beginners to Julia will benefit too)
Main is the top-level module, and Julia starts with Main set as the current module. Variables defined at the prompt go in Main, and varinfo() lists variables in Main.
Which also explains why “interactive REPL” is listed as construct introducing a global scope in Scope of Variables · The Julia Language – because it creates the module “Main” (and modules always introduce global scopes)
Technically, the REPL doesn’t create the module Main but it evaluates all its input into that module. Main exists even if the REPL is disabled (like in the julia myfile.jl case).