Modules & Selective Imports
Canonical module resolution, visibility (pub), selective from ... use imports, aliases, and multi-file projects in Wysna.
Wysna organizes code into explicit file-based modules with clear visibility boundaries and zero implicit global namespace pollution.
1. Whole-Module Namespace Imports
Section titled “1. Whole-Module Namespace Imports”Import a standard library module or local relative file with import "<path>", optionally assigning an alias with as:
import "std/json"import "std/text" as txtimport "./pricing.wysna" as pricing
fn main() -> unit { let clean = txt.trim(" wysna ") print(clean)}2. Selective Imports (from ... use)
Section titled “2. Selective Imports (from ... use)”Both Seed and the Self-Hosted Native SDK support selective imports with from ... use, eliminating repetitive module prefixes and reducing token overhead by ~13–22% in dense code:
# Single symbolfrom std.path use join
# Multiple symbols with trailing comma and local aliasfrom std.text use { contains, to_lower, split as text_split,}
# Local module importfrom "./domain/quote.wysna" use { Quote, quote_total,}3. Visibility (pub) & Encapsulation
Section titled “3. Visibility (pub) & Encapsulation”Declarations are private to their module by default. Mark functions, structs, enums, classes, interfaces, and exported tuple bindings with pub to expose them across module boundaries:
let INTERNAL_CAP = 10000
pub struct LineItem { pub sku: str pub unit_price_cents: int pub quantity: int}
pub fn line_total(item: LineItem) -> int { return item.unit_price_cents * item.quantity}
pub let (DEFAULT_CURRENCY, DEFAULT_TAX_BPS) = ("USD", 1500)Attempting to access a non-pub declaration from another module triggers compile-time diagnostic [W3002].
When building a library or framework, use pub import inside src/lib.wysna to re-export internal modules cleanly through a single entrypoint:
# src/lib.wysna — public library barrelpub import "./router"pub import "./middleware"
pub fn version() -> str { return "1.0.0"}4. Resolution & Security Rules
Section titled “4. Resolution & Security Rules”- Standard Library (
std/*): Always resolves against the installed SDK’s bundledstdlib/root. The compiler rejects parent-directory traversal (..) and symlinks escaping the standard library directory, and never silently falls back to the current working directory. - Relative Imports (
./): Resolve relative to the importing source file. Circular module cycles are rejected with[W1003]. - Package Dependencies (
pkg/<alias>/<module>): Install dependencies withwysna add <spec>(wysna.toml+wysna.lock) and import them anywhere viaimport "pkg/<alias>/<module>"orfrom "pkg/<alias>/<module>" use { ... }. Direct and transitive dependencies resolve automatically. See Packages, Libraries & Frameworks and Projects & Lockfiles.