timrandg
timrandg
MModular
Created by timrandg on 12/4/2023 in #questions
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?!?!?
2 replies