# Difference between “using” and “include”?

**URL:** <https://discourse.julialang.org/t/difference-between-using-and-include/121708>\
**Category:** General Usage\
**Created:** [October 24, 2024, 1:39pm UTC](https://discourse.julialang.org/t/difference-between-using-and-include/121708 "2024-10-24T13:39:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon91151494](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@anon91151494](https://discourse.julialang.org/u/anon91151494)\
**Post date:** [October 24, 2024, 1:39pm UTC](https://discourse.julialang.org/t/difference-between-using-and-include/121708/1 "2024-10-24T13:39:22Z")

</div>

> [@Difference between "using" and "include"?](https://discourse.julialang.org/t/difference-between-using-and-include/1739/3):
>
> Julia’s `include` is a function, _not_ a simple input redirector (as in C, Fortran, or Matlab). The documentation says (emphasis mine)

I found this question while trying to answer this question. It would be useful to know more about what actually happens instead of the simple text substitution which the C/C++ preprocessor performs.

I would guess that in Julia, `include` parses the target file and generates an AST.

What I’m interested in understanding is what happens if you include a file more than once, possibly in multiple places.

Does Julia do something to make sure it doesn’t end up with multiple copies of the same AST loaded from the same file?

Btw I could be mistaken. Maybe `include` does not create an AST.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [October 24, 2024, 2:59pm UTC](https://discourse.julialang.org/t/difference-between-using-and-include/121708/2 "2024-10-24T14:59:37Z")

</div>

Let’s keep this discussion in one place:

> [@What does \`include\` do?](https://discourse.julialang.org/t/what-does-include-do/121699/):
>
> There have been questions about this before, but so far none of them have provided an answer at the level of detail I have been looking for. My current understanding is that include is not a simple text substitution/replacement operation, which is how the C/C++ preprocessor works. Those languages simply substitute the line include("myfile.c") with the contents of myfile.c whenever such an include statement is encountered. Actually, in C/C++ the statement is #include "myfile.c" but you get the…

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [October 24, 2024, 2:59pm UTC](https://discourse.julialang.org/t/difference-between-using-and-include/121708/3 "2024-10-24T14:59:41Z")

</div>



---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [October 24, 2024, 3:00pm UTC](https://discourse.julialang.org/t/difference-between-using-and-include/121708/4 "2024-10-24T15:00:36Z")

</div>


