Does importing a module load all methods defined in that module?

This is just to confirm my understanding.

Based on Julia’s behavior, the following statement seems to be true: Any import or using statement loads a module, and loading adds all methods defined in that module to their respective method tables.

So, if I do import SomeModule or using SomeModule: some_function, if SomeModule defines any methods for some other function (let’s say LinearAlgebra.mul!), the updated method for LinearAlgebra.mul! will be loaded into my program as well. There is no way to use/import anything from SomeModule without getting the updated LinearAlgebra.mul! method, short of manually manipulating method tables, right? (Of course, I won’t notice any of this unless I import LinearAlgebra.mul! in my own program).

Just to be clear: I’m totally fine with this behavior, and I kinda think it’s the only behavior that really makes sense, but it took me a while to wrap my head around when originally learning Julia. Still, I haven’t seen it explicitly stated in the documentation.

Yes, that’s exactly correct. (And yes, I know you’re not new to Julia but this sort of information will be helpful in #first-steps :))

6 Likes