1
Cordial Quickstart
jess edited this page 2026-04-15 09:38:07 -07:00
Cordial Quickstart
Eval line
/= 2 + 2
→ 4
Variables and functions in scope
let m = 100
let v = 9.8
/= 0.5 * m * v^2
→ 4802
Types
let count: int = 42
let bad: int = 3.7 // ERROR — lossy round-trip
Value types: int, float, bool, str. Anything else is a unit label — see SPICE.
Functions
Math-style, single expression:
let area(w, h) = w * h
let hypot(a, b) = sqrt(a^2 + b^2)
/= area(4, 5) // → 20
/= hypot(3, 4) // → 5
Block-bodied:
fn classify(x) {
if x > 0 {
return "positive"
} else if x < 0 {
return "negative"
}
return "zero"
}
/= classify(-7) // → "negative"
With types:
fn area_typed(w: float, h: float) -> float {
return w * h
}
Control flow
let i = 0
let total = 0
while i < 10 {
total = total + i
i = i + 1
}
for x in [10, 20, 30] {
total = total + x
}
for n in 1..5 {
total = total + n
}
Implicit multiplication
2pi // 2 * pi
3x // 3 * x
4(a + b) // 4 * (a + b)
Tables
| Item | Cost | Tax (8%) |
| ------- | ----- | ------------ |
| Coffee | 4 | /= B2 * 0.08 |
| Bagel | 3 | /= B3 * 0.08 |
/= sum(@Items:B2:B10)
See also
Acord
The editor
Cordial
Power tools
Contributors