nenu-lang / files-and-declarations
StableFiles And Declarations
- A .nenu file contains either one entity definition or executable runnable steps—never both.
- Write Type name = value, or use a first assignment when the right side has a concrete type.
- Braces construct values; parentheses call functions or fetch records.
The Two File Contexts
code
1entity Expense {2 room_id: string @index3 payer: User4 title: string5 amount: number6 note: string?7 receipt: image?8 status: ExpenseStatus9}Reusable type, enum, default, and fn definitions may accompany either context. Top-level executable statements may not appear beside an entity definition, and a file may not define two entities.
Explicit And Inferred Locals
code
1string title = "Internet"2number amount = 72.503bool receipt_attached = false45note = "August bill"6share_count = 378string[] tags = []9Expense? selected- An explicit declaration always places the type before the lowercase local name.
- A simple first assignment declares a local only when the right side has an inferable concrete type.
- Empty arrays, empty maps, and
?are ambiguous; write their type explicitly. - A later assignment to the same simple name updates that local.
selfis reserved for the current receiver inside an attached function.
Construction, Calls, And Fetches
| Form | Meaning | Example |
|---|---|---|
Type { ... } | Construct a named value. | ExpenseDraft { title, amount } |
{ ... } | Construct a map or inferred structural value. | { title, amount } |
name(...) | Call a function. | splitAmount(total, count) |
Entity(...) inside need | Fetch durable data. | Room(request.room_id) |
Field Shorthand And Assignment
code
1room_id = request.room_id2title = request.title3amount = request.amount45expense = Expense {6 room_id7 payer: current_payer8 title9 amount10 note: ?11 receipt: ?12 status: ExpenseStatus.Draft13}1415expense.title = "Internet and utilities"16amount = amount + 5A bare field inside braces is shorthand for field: field. Use field: expression when the value is renamed, dotted, or computed. Dotted and indexed targets only update existing values; they never declare locals.
Reference Aliases
code
1alias payer = expense.payer2alias first_share = shares[0]3alias balance = balances[room_key]aliasgives a shorter reference-like name to an existing path or index access.- The right side must be a path or index expression—not a literal, constructor, or function call.
- Page Script supports a reference alias at top level as page state. Inside a handler or effect body, use an ordinary typed local because alias is not a browser runtime statement.
Common Mistakes
| Wrong | Correct |
|---|---|
let amount = 10 | number amount = 10 or amount = 10 |
const room = ... | Room room = ... or a valid alias path |
new Expense { ... } | Expense { ... } |
expense = [] | Expense[] expenses = [] |
alias amount = 10 | number amount = 10 |
