Syntax Reference
Complete reference for Calor syntax. Calor uses Lisp-style expressions for all operations.
Why this syntax? Calor's notation is optimized for AI agents, not human aesthetics. You don't need to learn this syntax—AI coding agents write Calor, not humans. This reference exists to help you understand what the AI generates and verify that contracts match your intent. Each design choice serves verification: unique IDs enable precise references, matched tags eliminate scope ambiguity, and Lisp-style expressions allow direct AST manipulation.
Quick Reference Table
| Element | Syntax | Example |
|---|---|---|
| Module | §M{id:name} | §M{m001:Calculator} |
| Function | §F{id:name:visibility} | §F{f001:Add:pub} |
| Async Function | §AF{id:name:visibility} | §AF{f001:FetchAsync:pub} |
| Method | §MT{id:name:visibility} | §MT{mt001:Process:pub} |
| Async Method | §AMT{id:name:visibility} | §AMT{mt001:ProcessAsync:pub} |
| Await | §AWAIT expr | §AWAIT §C{GetAsync} §/C |
| Lambda (inline) | (params) → expr | (x) → (* x 2) |
| Lambda (block) | §LAM{id:params}...§/LAM{id} | §LAM{l1:x:i32}...§/LAM{l1} |
| Delegate | §DEL{id:name}...§/DEL{id} | §DEL{d1:Handler}...§/DEL{d1} |
| Event | §EVT{id:name:vis:type} | §EVT{e1:Click:pub:EventHandler} |
| Subscribe | §SUB event handler | §SUB btn.Click OnClick |
| Unsubscribe | §UNSUB event handler | §UNSUB btn.Click OnClick |
| Input | §I{type:name} | §I{i32:x} |
| Output | §O{type} | §O{i32} |
| Effects | §E{codes} | §E{cw,fs:r,net:rw} |
| Requires | §Q expr | §Q (>= x 0) |
| Ensures | §S expr | §S (>= result 0) |
| For Loop | §L{id:var:from:to:step} | §L{l1:i:1:100:1} |
| While Loop | §WH{id} condition | §WH{w1} (> i 0) |
| Do-While Loop | §DO{id}...§/DO{id} cond | §DO{d1}...§/DO{d1} (< i 10) |
| If/ElseIf/Else | §IF...§EI...§EL | §IF (> x 0) → §R x §EL → §R 0 |
| Call | §C{target}...§/C | §C{Math.Max} §A 1 §A 2 §/C |
| C# Attribute | [@Name] or [@Name(args)] | [@HttpPost], [@Route("api")] |
§P expr | §P "Hello" | |
| Return | §R expr | §R (+ a b) |
| Binding | §B{name} expr | §B{x} (+ 1 2) |
| Operations | (op args...) | (+ a b), (== x 0) |
| Close tag | §/X{id} | §/F{f001} |
| List | §LIST{id:type} | §LIST{nums:i32} |
| Dictionary | §DICT{id:kType:vType} | §DICT{ages:str:i32} |
| HashSet | §HSET{id:type} | §HSET{tags:str} |
| Key-Value | §KV key value | §KV "alice" 30 |
| Push | §PUSH{coll} value | §PUSH{nums} 5 |
| Put | §PUT{dict} key value | §PUT{ages} "bob" 25 |
| Set Index | §SETIDX{list} idx val | §SETIDX{nums} 0 10 |
| Contains | §HAS{coll} value | §HAS{nums} 5 |
| Count | §CNT{coll} | §CNT{nums} |
| Dict Foreach | §EACHKV{id:k:v} dict | §EACHKV{e1:k:v} ages |
| Switch | §W{id} expr | §W{sw1} score |
| Case | §K pattern → result | §K 200 → "OK" |
| Wildcard | §K _ | §K _ → "default" |
| Relational | §PREL{op} value | §PREL{gte} 90 |
| Var Pattern | §VAR{name} | §VAR{n} |
| Guard | §WHEN condition | §WHEN (> n 0) |
Types
| Type | Description | C# Equivalent |
|---|---|---|
i32 | 32-bit integer | int |
i64 | 64-bit integer | long |
f32 | 32-bit float | float |
f64 | 64-bit float | double |
str | String | string |
bool | Boolean | bool |
void | No return value | void |
?T | Optional T | T? (nullable) |
T!E | Result (T or error E) | Result\<T, E\> |
Operators
| Category | Operators |
|---|---|
| Arithmetic | +, -, *, /, % |
| Comparison | ==, !=, <, <=, >, >= |
| Logical | &&, ||, ! |
All operators use Lisp-style prefix notation: (+ a b), (&& x y)
Effect Codes
| Code | Effect | Description |
|---|---|---|
cw | Console write | Console.WriteLine |
cr | Console read | Console.ReadLine |
fs:w | Filesystem write | File system writes |
fs:r | Filesystem read | File system reads |
fs:rw | Filesystem read/write | File system read and write |
net:r | Network read | HTTP GET, etc. |
net:w | Network write | HTTP POST, etc. |
net:rw | Network read/write | HTTP, sockets, etc. |
db:r | Database read | Database queries |
db:w | Database write | Database mutations |
db:rw | Database read/write | Database operations |
ID Conventions
| Element | Convention | Example |
|---|---|---|
| Modules | m001, m002 | §M{m001:Calculator} |
| Functions | f001, f002 | §F{f001:Add:pub} |
| Loops | for1, while1, do1 | §L{for1:i:1:10:1} |
| Conditionals | if1, if2 | §IF{if1} condition |
Complete Example
Plain Text
§M{m001:FizzBuzz}
§F{f001:Main:pub}
§O{void}
§E{cw}
§L{for1:i:1:100:1}
§IF{if1} (== (% i 15) 0) → §P "FizzBuzz"
§EI (== (% i 3) 0) → §P "Fizz"
§EI (== (% i 5) 0) → §P "Buzz"
§EL → §P i
§/I{if1}
§/L{for1}
§/F{f001}
§/M{m001}Detailed Reference
- Structure Tags - Modules, functions, closing tags
- Types - Type system, Option, Result
- Expressions - Lisp-style operators
- Control Flow - Loops, conditionals
- Contracts - Requires, ensures
- Effects - Effect declarations