What's the thing with global variables?

From what I've tried, using the global variables like this
var some_global_var: String = "Hey!"

fn main():
print(some_global_var)
var some_global_var: String = "Hey!"

fn main():
print(some_global_var)
works when you just run your code, but doesn't work in compiled executables. I've seen some folks mentioning this here on this server, but I can't seem to find any relevant docs on this, as well as I don't understand whether it's a bug, or am I supposed to work with global variables somehow differently. Any info on this would help, thanks!
4 Replies
toasty
toasty2w ago
They’ve said that it results in undefined behavior, so it’s not really supported at this time. Hopefully soon! You can define top level constants using alias though
Tyoma Makeev
Tyoma Makeev2w ago
Ah, ok, thanks for the clarification! Is there a bug for this or something else where I coud track the progress on this (assuming it's planned)?
Ryulord
Ryulord2w ago
GitHub
Global variables are not fully supported · Issue #1573 · modularml/...
Bug description run this code: from python import Python var mod_global :PythonObject = None fn main() raises: let mod_xml : PythonObject = Python.import_module("lxml") # let mod_global :...
Tyoma Makeev
Tyoma Makeev2w ago
great, thanks!
Want results from more Discord servers?
Add your server