Soft vs Hard Scopes, Macros, and `@everywhere`

I don’t think its really related to scope. The docs for @everywhere actually do give a hint, they say the expression is evaluated under Main, so even when @everywhere x = 1 is inside Foo, it sets a variable x in the Main module.

Depending where you actually want the variable, you could @everywhere @eval Foo x = 1 to instead set it inside Foo (note you need to define the module on the workers too, so put another @everywhere around the module definition), or you could print(Main.x) instead.

3 Likes