M
Modular10mo ago
timrandg

global variable declarations not consistent?!?!

#hello_world.mojo hello_world = 'hello_world' def main(): print(hello_world) print('hello_world_1') main() Then running on the commandline with "mojo hello_world.mojo" Strangely, this simple program has variable output on a M1 mac laptop (MacOS 13.4.1). Sometimes it prints hello_world1 and sometimes it prints hello_world1 Hello, world! var and let both behave the same, seemingly random failure to set the variable hello_world. Moving the line declaring hello_world into the function makes the program's output reliable, always printing both messages. This suggests that global variables assignment does not cause an error, but randomly fails, right?!?!?
1 Reply
timrandg
timrandg10mo ago
GitHub
[BUG] Cannot access global variables? · Issue #94 · modularml/mojo
Bug Description In the playground notebook, if I create a global variable (i.e. outside any function body) and try to access it within a function, it results in an unknown declaration error. For Py...
Want results from more Discord servers?
Add your server