A crystallization-based programming language
Variables in Lattice exist in phases, like matter. They start as mutable flux,
and crystallize into immutable fix with freeze(). Need to change them again?
thaw() brings them back to flux. Forge blocks let you build complex immutable
structures through controlled mutation.
// Forge blocks: controlled mutation that crystallizes fix config = forge { flux temp = Map::new() temp.set("host", "localhost") temp.set("port", "8080") temp.set("debug", "true") freeze(temp) } // config is now permanently immutable print(config.get("host")) // "localhost" print(phase_of(config)) // "crystal"
Lattice structs can hold closures as fields, giving you flexible object-like patterns with explicit data flow.
struct VendingMachine { balance: Int, inventory: Map, insert_coin: Fn, select_item: Fn, dispense: Fn } fn make_vending_machine() -> VendingMachine { flux inv = Map::new() inv.set("cola", 150) inv.set("chips", 100) inv.set("candy", 75) return VendingMachine { balance: 0, inventory: inv, insert_coin: |self, amount| { self.balance + amount }, select_item: |self, item| { let price = self.inventory.get(item) if self.balance < price { "insufficient funds" } else { "ok:" + item } }, dispense: |self, item| { let price = self.inventory.get(item) let change = self.balance - price "Dispensing " + item + "! Change: " + to_string(change) } } }
A small, focused language that gets the fundamentals right.
Variables exist as mutable flux or immutable fix. Transition with freeze(), thaw(), and forge blocks.
Closures capture their environment and work as values. Pass them to functions, store them in structs, return them from anywhere.
Struct fields can hold closures with self access, giving you object-like patterns with explicit data flow.
if/else, match, and blocks are all expressions that return values. Less boilerplate, more clarity.
Structured error handling with try/catch blocks. No hidden panics — errors are explicit and recoverable.
The interactive REPL is written in Lattice itself. Multi-line input, history, and expression evaluation built in.
Lattice is written in C with no external dependencies. Build from source in seconds.
Clone the repository
git clone https://github.com/ajokela/lattice.git
Build with make
cd lattice && make
Run a program or launch the REPL
./clat examples/phase_demo.lat
Or start the interactive REPL
./clat