Question: question on module vs. module with option package

I can't figure exactly why adding export on module wide variable when using option package makes the variable not writable from a function inside the module

restart;

dsolver :=module()
option package;
export X::boolean := true;

export foo:=proc()
   dsolver:-X :=false;
end proc;
end module;

dsolver:-foo();

Error, (in foo) attempting to assign to `X` which is protected.  Try declaring `local X`; see ?protect for details.

But this works

dsolver :=module()
export X::boolean := true;

export foo:=proc()
   dsolver:X :=false;
end proc;
end module;

dsolver:-foo();

    false;

I wanted to make the variable export, so it can be set from anywhere (by other modules for example, directly). if I make it local, then other modules can no longer access it?

I know I can change the export to local as the error says. But why is this needed? Only thing I found so far, is this

"Not all modules are packages. Package semantics differ from module semantics in two ways. First, (module-based) package exports are automatically protected. Second, packages can be used as the first argument to"

So the above says function inside module, can't change module wide variable, if this variable is exprted, when using option package? Why?

In general, I am still not sure when to use option package or not. 

Are there any general rules as to when one needs to add option package vs. Not using this option? i.e. just use module() without this option? or the question is: When must one use option package?

I put everything (all modules) eventually in an .mla file and both cases work the same in this respect, so not sure when to use this option now. 

Maple 2020.2 on windows 10

Please Wait...