latch-lang-0.2.0 is not a library.
Write .lt scripts to automate file operations, run shell commands, make HTTP calls, and orchestrate parallel tasks — all in a clean, readable syntax with zero boilerplate.
# deploy.lt
:= or
:= ?. ??
:= . |>
:=
in =4
0
Install
From crates.io (recommended)
From source
Pre-built binaries
Download from Releases and add to your PATH.
After install, verify:
# → latch v0.2.0
Quick Start
Create hello.lt:
:=
:=
Run it:
Features
| Feature | Example |
|---|---|
| Variables | name := "latch" |
| Type annotations | port: int := 8080 |
| String interpolation | "Hello ${name}!" |
| Lists & Dicts | [1, 2, 3], {"key": "val"} |
| Functions | fn greet(name) { return "hi ${name}" } |
| Anonymous functions | fn(x) { return x * 2 } |
| If / Else | if x > 0 { ... } else { ... } |
| For loops | for item in list { ... } |
| Range loops | for i in 0..10 { ... } |
| Parallel | parallel f in files workers=4 { ... } |
| Error handling | try { ... } catch e { ... } |
| Fallback values | data := fs.read("x") or "default" |
| Null coalesce | name := config?.name ?? "anonymous" |
| Safe access | resp?.headers, val?.field |
| Pipe operator | list |> sort() |> filter(fn(x) { return x > 2 }) |
| Membership test | "x" in list, "key" in dict |
| Range literal | 1..10 → [1, 2, ..., 9] |
| Compound assign | count += 1, total *= 2 |
| Modulo | 10 % 3 → 1 |
| Exit codes | stop 0 / stop 1 |
| Null literal | x := null, x == null |
| File I/O | fs.read, fs.write, fs.append, fs.readlines, fs.exists, fs.glob, fs.mkdir, fs.remove, fs.stat |
| Shell commands | proc.exec("cmd"), proc.exec(["git", "status"]), proc.pipe([...]) |
| HTTP | http.get(url), http.post(url, body) → HttpResponse |
| JSON | json.parse(str), json.stringify(value) |
| Env vars | env.get(key), env.set(k, v), env.list() |
| Path utils | path.join, path.basename, path.dirname, path.ext, path.abs |
| Time | time.now(), time.sleep(ms) |
| AI | ai.ask(prompt), ai.summarize(text) |
| Index mutation | list[0] = 5, dict["key"] = val |
| Higher-order | sort(list), filter(list, fn), map(list, fn), each(list, fn) |
| String utils | lower, upper, starts_with, ends_with, trim, split, replace |
| Comments | # hash and // line comments |
| REPL | latch repl |
CLI
Operators
| Operator | Description | Precedence |
|---|---|---|
|> |
Pipe (inject as first arg) | 1 (lowest) |
or |
Error fallback | 2 |
?? |
Null coalesce | 3 |
|| |
Logical OR | 4 |
&& |
Logical AND | 5 |
== != |
Equality | 6 |
< > <= >= in |
Comparison / membership | 7 |
.. |
Range | 8 |
+ - |
Add / subtract / concat | 9 |
* / % |
Multiply / divide / modulo | 10 |
! - |
Unary not / negate | 11 |
. ?. [] () |
Access / safe access / index / call | 12 (highest) |
Compound: += -= *= /= %=
Standard Library
Built-in Functions
# Print to stdout
# → 3
# → "42"
# → 7
# → 3.14
# → "string"
# → [1, 2, 3]
# → ["a"]
# → [1]
# → [0, 1, 2, 3, 4]
# → ["a", "b", "c"]
# → "hi"
# → "hello"
# → "HELLO"
# → true
# → true
# → true
# → "f00"
# → [1, 2, 3]
Modules
# fs — File System
:=
:=
:=
:= # → {size, is_file, is_dir, readonly}
# proc — Processes
:=
:= # array form (no shell)
:=
# http — HTTP Client (returns HttpResponse)
:=
# 200
# response body
# headers dict
:=
# json — JSON
:=
:=
# env — Environment Variables
:= or
# current process only
:=
# path — Path Utilities
:=
# → c.txt
# → /a/b
# → gz
# time — Time
:= # RFC 3339 timestamp
# Sleep 500ms
# ai — AI (requires LATCH_AI_KEY env var)
:=
:=
Error Messages
Latch produces structured, actionable errors:
[latch] Semantic Error
file: deploy.lt
line: 12 col: 5
→ result := undeclared_var + 1
reason: Undefined variable 'undeclared_var'
hint: Declare the variable first with ':='
Parallel Execution
Parallel blocks run all workers to completion. If any worker fails, the first error is returned after every worker has finished — no silent partial failures.
:=
in =4
Use as CI Exit Code
:=
0
Examples
See the examples/ directory:
hello.lt— Feature showcaseci-check.lt— CI gate examplev02_test.lt— v0.2.0 feature tests
Full Reference
See docs/stdlib.md for the complete standard library reference.
License
MIT — see LICENSE