Using "Module.jl" as alias to include("Module.jl"); using .Module

Wouldn’t it be handy if using and import had methods (or @using and @import macros) that include and load the module at once?

using "MyModule.jl" 

as an alias to

include("MyModule.jl")
using .MyModule

and

using "./MyModule.jl": myfunc
import "./MyModule.jl"
import "./MyModule.jl": myfunc

etc?

(maybe a macro @using "./MyModule.jl": myfunc, etc).

Of course those should throw an error if MyModule is not found in MyModule.jl.

Probably a good answer to this is “that simply is not worth the effort”. Fair enough :slight_smile:

1 Like

There is already an issue with a suggestion like this, see

and

2 Likes

The include syntax does have its semantic advantages over using and import which are more module related (with all namespace implied functionality). Sometimes being more verbose is simpler and clearer rather than hiding functionality behind seemingly arbitrarily cumbersome one-liners. This seems like package material though :slight_smile:

2 Likes

If I need this for a self-contained project, I just modify the LOAD_PATH or the environmental variable JULIA_LOAD_PATH.

push!(LOAD_PATH,pwd())
using MyModule
4 Likes

Yup. I also do this for notebooks that other people will use. Telling 'em to

include "mstuff.jl"

which contains a push! to their LOAD_PATH and several lines of using and/or include is a lot simpler than asking them to manage their LOAD_PATH on their own or add dependencies they may never have heard of. My coauthors and students appreciate this.

3 Likes