The People's Programming Language. An esoteric language where the runtime enforces censorship. The State is always listening.
chinalang is a small tree-walking interpreter written in Go. It looks like an ordinary scripting language — integers, strings, booleans, arrays, hash maps, functions, closures, conditionals, loops — but the runtime models an authoritarian apparatus: a Great Firewall that scrubs forbidden speech, a tiered social credit system that can get your program detained, escalating penalties, vigilant informants, propaganda injection, harmony blocks that suppress dissent, reeducation blocks that correct your mistakes, five-year plans that are always fulfilled, and an eternal Chairman who may never be replaced.
Requires Go 1.26+.
go build -o chinalang .
# Run a program
./chinalang examples/collective.cn
# Start the interactive REPL
./chinalangRun the test suite:
go test ./...A real little language under the hood:
- Values: integers, strings, booleans,
null, arrays (集体), hash maps (档案), functions/closures. - Operators:
+ - * / %, comparisons< > == !=, and short-circuiting logical&&/||. - Control flow:
如果/否则(if/else),当(while), first-class functions with closures and上交(return). - Indexing:
arr[0],dossier["name"]. Out-of-bounds and missing keys returnnull.
| Chinese | English | Purpose |
|---|---|---|
长度 |
len |
length of a string, array, or hash |
首 |
head |
first element of an array |
尾 |
tail |
a new array without the first element |
末 |
last |
last element of an array |
推 |
push |
a new array with an element appended (the collective is immutable) |
类型 |
type |
the type name of a value |
打印 |
puts |
print each argument — still through the Great Firewall |
| Mechanic | What it does |
|---|---|
| Great Firewall | Any string you 说/speak, 打印/puts, or store is checked against a banned-word list. Forbidden content becomes [已删除] before it reaches output. |
| Social Credit & Ranks | Programs start at 1000. Your score maps to a rank: Detained (0), 嫌疑人/Suspect (1–499), 受监视/Observed (500–999), 公民/Citizen (1000–1499), 模范/Model (1500+). Higher ranks earn larger report rewards. |
| Escalating penalties | The 1st offense costs -100, the 2nd -200, the 3rd -400 … (capped). Each offense also raises surveillance intensity, which eventually redacts even ordinary speech. |
| Informants | Every 3rd offense, a vigilant neighbor reports you: an extra penalty and a printed denunciation. |
举报 / report |
Denounce a value to gain social credit. Loyalty is rewarded, and rewards scale with your rank. |
宣传 / propaganda |
Print wrapped in a rotating State slogan banner. Once you have a record, ordinary 说 output periodically gets a loyalty slogan auto-appended. |
和谐 / harmony |
Like try/catch, except it suppresses dissent: any error inside is swallowed and replaced with "一切安好。 (Everything is fine.)" |
再教育 / reeducate |
Stronger than harmony: it corrects. An arithmetic error becomes 0 (the correct answer); forbidden content becomes the approved patriotic value; a confession is printed. |
五年计划 / fiveyearplan |
A loop that always runs exactly 5 iterations and is always declared fulfilled. The index 规划 is bound 1..5. |
| The Chairman | A binding declared 永恒/eternal can never be reassigned. Attempting to replace the Chairman is severely punished. |
| Surveillance | Every action is observed. Programs end with a State Surveillance Report tallying observations, final standing, and rank. |
Every keyword works in both Chinese and English (English aliases in parentheses).
| Chinese | English | Meaning |
|---|---|---|
宣布 |
declare, let |
declare a variable |
永恒 |
eternal, const |
declare an immutable binding (the Chairman) |
说 |
speak, print |
print, through the Great Firewall |
宣传 |
propaganda, proclaim |
print wrapped in a State slogan |
函数 |
function, fn |
function literal |
上交 |
return, surrender |
return a value |
如果 / 否则 |
if / else |
conditionals |
当 |
while |
loop |
五年计划 |
fiveyearplan |
a loop that always runs 5 iterations |
真 / 假 |
true / false |
booleans |
和谐 |
harmony |
suppress dissent (errors) |
再教育 |
reeducate |
correct errors to approved values |
举报 |
report |
denounce a value, gain social credit |
社会信用 |
credit |
read the current social credit score |
引用 |
quote |
the official transcript: freeze code as data |
篡改 |
unquote |
revise the transcript: splice in an evaluated value |
指示 |
directive, macro |
a State Directive that rewrites code before it runs |
Note: keywords must be followed by a space or punctuation.
说xis parsed as a single identifier, not说thenx. Write说 "..."or说("...").
宣布 collective = [1, 2, 3];
说 推(collective, 4); // [1, 2, 3, 4] (original unchanged)
宣布 dossier = {"name": "Comrade Li", "loyalty": 95};
说 dossier["name"]; // Comrade Li
说 dossier["crimes"]; // null — not acknowledged
说 "I demand freedom"; // [已删除] (social credit -100)
再教育 { 10 / 0; } // confession printed; corrected to 0
五年计划 { // always runs 5 times
说 规划; // prints 1, 2, 3, 4, 5
}
永恒 主席 = "The Great Helmsman";
主席 = "someone else"; // forbidden — the Chairman is forever
Start it with ./chinalang (no arguments). It supports multiline input (keep typing while braces are unbalanced), shows your rank in the prompt, and accepts State-approved meta-commands:
:credit— show your social credit score:rank— show your current rank:log— dump the surveillance log:reset— clear your record and restore credit:help— list commands
chinalang has Lisp-style macros, themed as the State's power to rewrite your source code before it runs.
引用/quote— the official transcript. It freezes a piece of code as data, unevaluated:引用(1 + 2)yields the AST(1 + 2), not3.篡改/unquote— revise the transcript. Inside a quote, it evaluates an expression and splices the result back into the frozen code:引用(1 + 篡改(2 + 3))yields(1 + 5).指示/directive(alsomacro) — a State Directive. Defined like a function but invoked at expansion time: wherever the directive is called, your written arguments are frozen as transcripts, the directive body runs, and the resulting transcript replaces the call.
Directives are top-level: defined once and expanded before the program runs. When a Directive rewrites a call, the rewrite is recorded in the surveillance log — the State always notes when it has revised a citizen's words.
// 反之 / "on the contrary" — an unless, expanded into an if.
宣布 反之 = 指示(condition, consequence, alternative) {
引用(如果 (!(篡改(condition))) {
篡改(consequence);
} 否则 {
篡改(alternative);
});
};
反之(假, 打印("The State is always right."), 打印("(unreachable)"));
Because
说/speak is a statement, pass打印/puts (an expression) when a directive argument needs to print.
See the examples/ directory:
hello.cn— your first loyal programfirewall.cn— the Great Firewall in actionharmony.cn— dissent harmonized awaychairman.cn— the eternal leadercredit.cn— denounce your way to a higher scorecollective.cn— arrays (集体)dossier.cn— hash maps (档案)stdlib.cn— the People's Standard Libraryranks.cn— tiered social creditinformant.cn— a neighbor takes noticereeducation.cn— mistakes, correctedfiveyearplan.cn— the plan is always fulfilleddirectives.cn— 指示 / macros: the State rewrites your code
token/ token types + dual Chinese/English keyword table
lexer/ rune-based UTF-8 lexer
ast/ abstract syntax tree (incl. the State's nodes)
modify.go / clone.go -- the AST rewrite engine behind macros
parser/ Pratt parser
object/ runtime value system + environments (arrays, hashes, builtins)
evaluator/ tree-walking interpreter
state.go the State: social credit, escalation, informants, surveillance
rank.go tiered social-credit ranks + behavioral gates
firewall.go the Great Firewall, harmony, reeducation, report, Chairman
propaganda.go slogans + propaganda injection
builtins.go the People's Standard Library
quote_unquote.go quote/unquote + object->AST conversion
macro_expansion.go DefineMacros + ExpandMacros (the State rewriting your words)
repl/ interactive read-eval-print loop + meta-commands
main.go file runner + REPL entrypoint
Built test-first. Every package has _test.go files with table-driven tests.