Why won't Julia let me put a module import within a function?

using modified bindings in the current module scope. If you’re inside a function, you’re not in a module scope. You could define it to operate in the module scope of whatever module encloses the function, but that probably doesn’t do what you want, since you may be calling it from some other module. If you do really want that behavior, you can use eval. As was pointed out, the correct way to factor top-level code is to use include or a macro. @johnmyleswhite is correct of course that the reason we don’t have any sort of dynamic scope for these things is that that would be gratuitous dynamism without any real benefit.

8 Likes