<p>Some languages allow you to import local (file system) files normally via some directives like <code>import</code>:</p>
<ul>
<li>In Dart: <code>import './file.dart';</code>.</li>
<li>In Rust: <code>mod some_file;</code> (imports <code>some_file.rs</code> or <code>some_file/mod.rs</code>)</li>
<li>Others (JavaScript)</li>
</ul>
<p>C# globs sources and Java is folder hierarchy-based.</p>
<p>One thing though is that some languages allow to insert AST into another AST (or text into text) from another program; that is, they include them almost literally, so they inherit the lexical scope etc. In C# if you need to split a class into multiple files, you use <code>partial</code> there.</p>
<p>What are languages that support this? For example, Rust's <code>include!(&quot;./src.rs&quot;)</code>.</p>

<syntax>
Languages with source include (AST or concatenated)
CC BY-SA 4.0
2023-07-20T14:05:06.653Z
Can you be clearer about what this question is asking? Is it about importing text from another file (like C #include), importing a module that happens to be on the file system rather than via a package path like in Java or AST macros?
Or do you mean something more like [C++ module partitions](https://en.cppreference.com/w/cpp/language/modules)?
Bruce Adams
CC BY-SA 4.0
2023-07-20T14:13:01.877Z
Is this about, whether a language should let you choose how to split your code into files freely, without attributing meaning to source file names? Or more specifically about language that give you an escape hatch to bypass their default attribution of meaning to source file names, e.g. by considering a file as merged into another?
Eldritch Conundrum
CC BY-SA 4.0
2023-07-20T14:21:45.780Z
@BruceAdams This is about importing text or the node tree from another file. Nothing related to modules!
Hydroper
CC BY-SA 4.0
2023-07-20T14:23:35.577Z
@EldritchConundrum It can be both of these.
Hydroper
CC BY-SA 4.0
2023-07-20T14:27:28.470Z
Our points are really that the question is not clear. 
The new module system of C++ gives you another way to split code over files so it might be relevant. As might [#embed](https://thephd.dev/finally-embed-in-c23).
Bruce Adams
CC BY-SA 4.0
2023-07-20T16:09:36.843Z
There is probably a good question here if you edit it.
Bruce Adams
<h1>Rust</h1>
<pre class="lang-rust prettyprint-override"><code>include!(&quot;foo.rs&quot;);
</code></pre>
<p><code>include!</code> is not recommended, but it may be useful for writing build tools that include dynamically-generated sources.</p>
<p>It can be used as an item or expression.</p>
<p>From <a href="https://doc.rust-lang.org/stable/std/macro.include.html" rel="nofollow noreferrer">https://doc.rust-lang.org/stable/std/macro.include.html</a>:</p>
<blockquote>
<p>The included file is placed in the surrounding code unhygienically.</p>
</blockquote>
<h1>Dart</h1>
<pre class="lang-dart prettyprint-override"><code>library lib;
part 'foo.dart';
</code></pre>
<p><strong>foo.dart</strong></p>
<pre class="lang-dart prettyprint-override"><code>part of lib;
</code></pre>
<p>I just discovered this <code>part</code> is not recommended by the docs.</p>
<h1>VioletScript</h1>
<pre><code>include 'foo.vs';
</code></pre>

CC BY-SA 4.0
2023-07-20T13:30:57.473Z
2023-07-20T16:31:29.433Z
2023-07-20T16:31:29.433Z
Hydroper
CC BY-SA 4.0
2023-07-20T13:57:12.900Z
Include is also not recommended in rust
mousetail 'he-him'
# Languages with source include (AST or concatenated)
Posted by: username_0 on 2023-07-20
Some languages allow you to import local (file system) files normally via some directives like `import`:

* In Dart: `import './file.dart';`.
* In Rust: `mod some_file;` (imports `some_file.rs` or `some_file/mod.rs`)
* Others (JavaScript)

C# globs sources and Java is folder hierarchy-based.

One thing though is that some languages allow to insert AST into another AST (or text into text) from another program; that is, they include them almost literally, so they inherit the lexical scope etc. In C# if you need to split a class into multiple files, you use `partial` there.

What are languages that support this? For example, Rust's `include!("./src.rs")`.
**Tags:** syntax
> **Comments:**
> **username_1**: Can you be clearer about what this question is asking? Is it about importing text from another file (like C #include), importing a module that happens to be on the file system rather than via a package path like in Java or AST macros?
Or do you mean something more like [C++ module partitions](https://en.cppreference.com/w/cpp/language/modules)?  
> **username_2**: Is this about, whether a language should let you choose how to split your code into files freely, without attributing meaning to source file names? Or more specifically about language that give you an escape hatch to bypass their default attribution of meaning to source file names, e.g. by considering a file as merged into another?  
> **username_0**: @BruceAdams This is about importing text or the node tree from another file. Nothing related to modules!  
> **username_0**: @EldritchConundrum It can be both of these.  
> **username_1**: Our points are really that the question is not clear. 
The new module system of C++ gives you another way to split code over files so it might be relevant. As might [#embed](https://thephd.dev/finally-embed-in-c23).  
> **username_1**: There is probably a good question here if you edit it.  
---
## 1 answers
### Answer by username_0 on 2023-07-20. Score: 3
Rust
include!("foo.rs");

include! is not recommended, but it may be useful for writing build tools that include dynamically-generated sources.
It can be used as an item or expression.
From https://doc.rust-lang.org/stable/std/macro.include.html:

The included file is placed in the surrounding code unhygienically.

Dart
library lib;
part 'foo.dart';

foo.dart
part of lib;

I just discovered this part is not recommended by the docs.
VioletScript
include 'foo.vs';
> **Comments:**
> **username_3** (2023-07-20): Include is also not recommended in rust  
---
