Declarations and control flow
Kinmokusei uses braces, optional statement semicolons, typed declarations, and explicit control flow. The syntax is TypeScript-inspired; evaluation and generated behavior are deliberately Go-shaped.
For a connected language treatment, read Source text, Bindings and scope, and Control flow in the Language Manual.
import go fmt from "fmt";
enum Status { Pending, Running = 4, Complete }
function total(values: int[]): int {
let result = 0;
for (const value of values) {
result += value;
}
return result;
}
function classify(status: Status): string {
switch (status) {
case Status.Pending { return "pending"; }
case Status.Running { return "running"; }
case Status.Complete { return "complete"; }
}
return "unknown";
}
function main(): void {
fmt.Println(total([2, 4, 6]), classify(Status.Complete));
}Expected output:
12 completeSource files and comments
Source files use the .km extension and UTF-8 text. Line comments begin with //; block comments use /* ... */. Every file has an independent module scope.
Semicolons terminate declarations and simple statements, but can be omitted at a completed line, before }, or at end of file. The two separators in a three-clause for remain required. Blocks, functions, classes, structs, interfaces, and switch clauses use braces. Keep a returned/thrown value on the keyword's line; see the termination rules for multiline expressions.
import go fmt from "fmt"
function main(): void {
const double = (value: int): int => {
return value * 2
}
const result = double(
21,
)
fmt.Println(result)
}Expected output: 42.
Bindings
Use const for a binding that will not be reassigned and let for one that will:
const serviceName = "api";
let attempts: int = 0;
attempts += 1;const protects the binding, not the storage behind a class reference, slice, map, pointer, or other reference-bearing value. Mutability and copy behavior come from the value's type.
Local bindings infer types from their initializer in Go-like cases. Parameters, results, fields, and other public boundaries use explicit types.
Scope and visibility
Bindings are lexical and shadowing is resolved by declaration identity. Relative imports are selective and explicit; transitive imports do not expose names.
Class and struct members use public, protected, or private where supported. Generated Go capitalization does not define Kinmokusei visibility—the compiler resolves visibility first and then chooses deterministic Go names.
Conditions
Conditions must be boolean; there is no truthy conversion.
if (ready) {
start();
} else {
wait();
}Loops
The language supports while, C-style for, and for-of range:
while (pending()) { poll(); }
for (let i = 0; i < 3; i++) { visit(i); }
for (const value of values) { consume(value); }
for (const [index, value] of values) { consumeAt(index, value); }
for (const [key, value] of lookup) { consumeEntry(key, value); }The single-binding range form always receives the value. String range yields an int UTF-8 byte offset and an int32 Unicode code point. Map order is unspecified. The range source evaluates once, and each range value is a copy.
Switch
Value switches compare one subject against source-ordered cases. The subject evaluates once; case expressions stop evaluating after the first match.
switch (status) {
case Status.Pending { queue(); }
case Status.Running, Status.Complete { observe(); }
default { reject(); }
}Cases do not fall through implicitly. An explicit final fallthrough; enters the next clause without evaluating its case expressions. Type-binding switches are reserved for Go interface values and use case const value as Type.
Branches, labels, and defer
break and continue may target labels. goto supports validated forward and backward transfer within one function. The checker rejects jumps into nested blocks, over declarations, or across lowered exception boundaries.
defer call(); preserves Go's deferred-call behavior. The call target and arguments follow Go-compatible evaluation rules.
Updates
Compound assignment and ++/-- are statements, never expressions:
counter++;
scores[key] += delta;Targets execute once. Constants, methods, string indexes, and non-addressable temporary fields are rejected; map indexes remain writable.
See Operators for precedence and operand rules.