Modules & imports
Namespace import
Import an entire module under its name and access members with a dot:
import strings
import math
strings.upper("hello") // "HELLO"
math.sqrt(16.0) // 4.0
Named import
Import specific exports directly into scope:
import { abs, sqrt, PI } from "math"
println(sqrt(PI))
Sub-modules
Many modules are organized into sub-modules, reached with further dot access after importing the parent:
import time
import net
import thread
time.clock.now() // current time, RFC3339
net.tcp.connect("localhost", 8080)
thread.mutex.new()
Local modules
Any .goost file is a module. Import it by name (without the extension) to use
its top-level functions:
// math_utils.goost defines fn clamp(...)
import math_utils
println(math_utils.clamp(15, 0, 10)) // 10
Resolution order
When you import name, Langoost resolves it in this order:
- Standard-library modules — always checked first; stdlib names cannot be shadowed by local files.
- Installed packages —
./langoost_modules/(so installed deps win over ambient files). See Packages. - Filesystem — the directory of the script being run, then the current working directory.
Packages
Langoost has a simple package manager. Declare dependencies in a
langoost.json manifest:
{
"name": "myapp",
"version": "0.1.0",
"dependencies": {
"router": "github:someone/langoost-router",
"shared": "file:../shared",
"json2": "https://example.com/json2.tar.gz"
}
}
Then run langoost install (see the CLI reference),
which fetches each dependency into ./langoost_modules/<name>/. Dependency
sources can be:
- Git —
git+https://…or thegithub:user/reposhorthand - Local paths —
file:../path/to/pkg - HTTPS archives — a
.tar.gzor.zipURL
Transitive dependencies are resolved from each package’s own manifest. Once
installed, import "name" finds the package by trying <name>.goost,
<name>/main.goost, then <name>/<name>.goost.
install writes a langoost.lock lockfile recording the resolved version
and content hash of every dependency. Commit it, then run langoost install --frozen for reproducible builds — it installs exactly what the lockfile pins
and fails on any mismatch. langoost verify re-hashes the installed modules
against the lockfile to detect drift or tampering, and langoost verify --signed additionally requires each entry to carry a valid ed25519 signature
from a trusted signer (see the CLI reference). There is
no semver resolution yet — it’s a pragmatic share-the-code workflow.
Module cache
Compiled modules are cached by absolute path and modification time. After the first import, unchanged modules are served from cache as a map lookup — no recompilation. In long-running server mode this keeps imports effectively free.
Browse everything available out of the box in the standard library.