Syntax · 6 of 6
Comments
Two comment styles, both ignored by the lexer.
Line comments
// This is a line comment.
let x = 42 // trailing comments work too
Block comments
/* This is a block comment.
It can span multiple lines. */
proc demo() { return 1 }
Practical examples
Documenting intent
proc transfer(from, to, amount) {
// Validate amount before touching the database — cheap fail.
if amount <= 0 { abort "invalid amount" }
if from == to { abort "self-transfer not allowed" }
// Load both accounts. We need sender for the balance check anyway.
let sender = find_one("accounts", {account_id: from})
let receiver = find_one("accounts", {account_id: to})
// MUST combine all field updates per doc — OCC validates per document.
update("accounts", {account_id: from}, {$inc: {balance: -amount, tx_count: 1}})
update("accounts", {account_id: to}, {$inc: {balance: amount, tx_count: 1}})
return {ok: true}
}
Disabling code temporarily
proc charge(account, amount) {
update("accounts", {_id: account}, {$inc: {balance: -amount}})
/* TODO: re-enable email notification once the
outbound queue is fixed (see #234)
insert("email_queue", {
to: account.email,
subject: "Receipt",
body: "..."
})
*/
return {ok: true}
}
Section dividers
proc place_order(user_id, items) {
// ────────── 1. Validate ──────────
if user_id == null { abort "user_id required" }
// ────────── 2. Reserve stock ──────────
for i in items {
update("products", {sku: i.sku}, {$inc: {reserved: i.qty}})
}
// ────────── 3. Charge ──────────
// (omitted)
return {ok: true}
}
Style guidance
- Comment why, not what. Names should explain the what.
- Call out invariants the OCC engine relies on (the "MUST combine all field updates per doc" comment above is gold).
- Reference issue numbers or PRs for temporary code.
- Block comments are great for large sections that are temporarily disabled — easier to spot than rows of
//.