Packages and files
A file contains exactly one package block. The package name is what imports refer to; the file name is free.
package money {
export struct Price {
amount: Int
currency: Str
}
}
Rules:
- A file without a
packageblock, or with more than one, is a compile error. - The package name is
lowercase_snake_case. Functions, fields, parameters, locals, and bindings aresnake_case; structs, enums, and variants arePascalCase. - Package identity is
(dependency, file path), not the name alone. Two dependencies may both declarepackage user; importing both into one file requires different aliases. - Type identity is nominal per loaded module.
money.Priceanduser.Pricenever unify, even with identical fields. - Case-insensitive uniqueness applies inside a package:
Formatandformatcannot coexist. - The package name, not the file name, determines the output module.
Visibility
export is per declaration. Without it, a declaration is private to its package.
package money {
export fn format_price(p: Price) -> Str { … }
fn round_to_cents(n: Int) -> Int { n } // private
}
Privacy applies to every call path: a plain name, a qualified path, and receiver sugar. Another package cannot reach round_to_cents through money.round_to_cents, and cannot call it as a receiver.
Local imports
Local imports start with ./ or ../. The specifier has no .lt extension; the loader appends it.
import money "./wallet/money"
import money { Price, format_price } "./wallet/money"
import money as cash { Price as P } "./wallet/money"
- Only whole packages are imported, never individual files or symbols.
- The package name is written explicitly and must exist in the target file.
- Destructuring is optional and may only name
exported declarations (or names the target package explicitly re-exports). It does not remove the qualifier:import money { Price }may still usemoney.format(...). - An empty destructuring list
{}is an error. - There are no directory imports and no
indexresolution. - Import cycles are compile errors and the message shows the cycle.
- An import that is never used is a compile error.
- Imports are not re-exported implicitly.
External imports
External dependencies are declared in lt.toml at the project root:
[dependencies]
acme = { git = "https://github.com/acme/lt-lib", version = "^1.2" }
utils = { path = "../utils" }
An external import is <dependency-key>/<package path>:
import post "acme/blog/post"
The first segment must be a key in [dependencies]. The rest is the package path inside that dependency. See Packages and dependencies and the import v3 design note.
Re-export
A package can expose imported names as part of its own API:
export import money { Price as P } "./wallet/money"
- The item list is mandatory; wildcards and the bare form are rejected.
- The re-exported name must be public in the source package.
- A re-export does not create a new type:
facade.Pandmoney.Priceare the same nominal type. - Re-exports do not propagate implicitly. Only the names listed are exposed; the package qualifier is not.
Commands
lt add foo --git https://github.com/foo/bar --version "^1.2"
lt add utils --path ../utils
lt remove foo
lt update foo
lt update --all
lt vendor
lt add writes lt.toml; lt update resolves and writes lt.lock; lt build and lt check never write the lock. An incomplete lock is an error. lt migrate --write rewrites v2 imports to v3.
Complete example
import wallet "./_wallet"
package qualified {
export fn checkout(subtotal: Int) -> Str {
wallet.format(wallet.add_vat(wallet.Money(amount: subtotal)))
}
test "qualified access reaches types, bindings and functions" {
expect.eq(checkout(100), "Rp111")
}
}
The support file imported by this case:
package wallet {
export struct Money {
amount: Int
}
export let vat: Int = 11
export fn add_vat(money: Money) -> Money {
Money(amount: money.amount + money.amount * vat / 100)
}
export fn format(money: Money) -> Str {
`Rp${money.amount}`
}
}