Difference between "using" and "include"?

Julia’s include is a function, not a simple input redirector (as in C, Fortran, or Matlab). The documentation says (emphasis mine)

include(path::AbstractString)
Evaluate the contents of a source file in the current context.

“The current context” means the global scope of the current module when the evaluation takes place. Continuing,

This function is typically used to load source interactively, or to combine files in packages that are broken into multiple source files.

and for those purposes the distinction usually doesn’t matter.

Another use for the textual “include” in other languages is reuse of code blocks in local contexts (where the Julia include function may do surprising things). A Julian pattern for this would use macros. A nice example is the @def macro used inside the DifferentialEquations.jl ecosystem. There, one includes a file containing @def macro definitions, the definitions are evaluated right then, and the macros are used to paste in blocks of code at parsing time.

2 Likes