Import
The import statement lets you use code from other VDX files. This enables code reuse and modular project organization.
Basic syntax
import "filename.vdx";Example
Create a utils file (utils.vdx):
// Top-level functions are callable directly after import
fn add(a, b) {
return a + b;
}
// Classes can also be imported — use them via new + dot-call
class Utils {
fn greet(name) {
return "Hello, " + name;
}
}Import and use it in your main file:
import "utils.vdx";
class Main {
let sum = add(5, 3);
print(sum); // 8 — top-level fn is callable directly
let u = new Utils();
print(u.greet("VDX")); // Hello, VDX — class method via object
}What gets imported
- Top-level functions become callable directly by name
- All class definitions become available for
newinstantiation — call their methods on an object (u.greet(...)), not as bare functions - Top-level statements in imported files are not executed
- Errors inside imported files report the imported file's name and lines (v0.1.5+)
Circular imports
VDX automatically prevents circular imports. If file A imports file B, and file B imports file A, the second import is silently skipped to prevent infinite loops — including a loop back through the entry file (v0.1.5+).
File paths
Import paths are relative to the importing file. Both relative paths ("./utils.vdx") and simple filenames ("utils.vdx") work.