Thunder Core: write a program in Thunder and run it
Thunder Core is the part of Thunder you write. You write instructions in plain words, Thunder checks them, compiles them to Python, and runs them. The generated Python is ordinary code you can read and keep.
main.thunder ──thunder check──▶ problems, in words, with a line and a code (TC1xx–TC4xx)
│
└──thunder build──▶ generated/python/main.py + thunder_runtime.py ──python──▶ output
│
a failure names the Thunder line ◀┘ (TC5xx)Status (v0). There are six compilation targets: Python 3.10+ (the default), TypeScript, C#, Java, Go, and Rust (see "Compile to …" below for each), plus the Thunder engine, which runs a program directly. Every Core test program gives the same output, errors included, on all of them; a target is listed only once it does. The rules below in "What a value means" are the rules every future target must keep.
Start#
You need Node.js 18+ (for the thunder command) and Python 3.10+ (to run what it builds).
npm install -g @skillstech/thunderlang # 1.1.0 or later has Thunder Core
thunder doctor # is everything ready? (Node.js, Python, PATH)
thunder new my-program # thunder.toml, src/main.thunder, tests/
thunder run my-program # check, build, and run itthunder new my-program --run does both. Inside the folder, the commands need no name:
cd my-program
thunder run # check, build, and run src/main.thunder
thunder test # run every Test block
thunder check # only check; nothing is written
thunder build # write the Python to generated/python/
thunder format --write # tidy indentation and spacingOutside a project, add --core to work with a single file: thunder run --core hello.thunder.
thunder init <Name> (also written thunder new --mission <Name>) still creates an intent mission file.
Missions describe what a feature must do. Core programs are code that runs. A .thunder file counts as Core
only when it is inside a folder with thunder.toml, or when you pass --core. Thunder never guesses.
thunder.toml:
[project]
name = "my-program"
version = "0.1.0"
[build]
target = "python" # or "typescript", or "go"
source = "src"
tests = "tests"
output = "generated/python"
entry = "main.thunder"thunder run and thunder test need Python 3.10 or newer. Set THUNDER_PYTHON to choose which one.
A first program#
# Lines starting with # are comments.
say "Hello, world!"
Set name to "Ada"
say "Nice to meet you, {name}."Each line starts with an action. A line that ends with : opens a block. The lines that belong to it are
indented by two spaces.
Statements#
| Write | Meaning |
|---|---|
say <value> (or print) |
show a value |
Set total to 0 |
give a name a value (names may be several words: tax rate) |
Set order's price to $5 · Set counts at word to 1 |
change a field of a record, or an entry in a map or list |
Keep tax rate at 7% |
a value that never changes |
Increase total by 5 · Decrease n by 1 |
change a number or money |
Add order to orders · Remove item from cart |
change a list (Add 5 to total also works for numbers) |
Sort scores · Reverse scores |
change a list in place |
When <condition>: (or If) … Otherwise when …: … Otherwise: |
choose |
For each order in orders: |
go through a list, a map, or text |
For each word and seen in counts sorted by value descending: |
go through a map's keys and values |
For each n from 1 to 10: |
count, including both ends |
Repeat while <condition>: · Repeat until <condition>: · Repeat 3 times: |
repeat |
Stop with "message" |
stop the program with a message (TC507) |
<statement> then If this fails: |
handle a failure of the statement just above; {error} is the message in words |
Use csv as csv |
use a Python module (see "Python libraries") |
Functions#
To calculate discount:
Receive total and member
When member is true and total is at least 100:
Give 20% of total
Otherwise:
Give 0
say calculate discount with 150 and trueReceive comes first: one line (Receive total and member) or one line per input. You can name the kind of
each input: Receive total as money, member as yes/no, or Receive member as yes or no.
An input can have a default, used when a call leaves it out:
To taxed price:
Receive price and rate (7% if not given)
Give price + price * rate
say taxed price with 100 # 107
say taxed price with 100 and 20% # 120A default is a fixed value: a number, money, a percent, text, yes/no, nothing, or a kept value. Inputs with a
default come after the inputs without one. A list or a map cannot be a default. In Python such a default is made once
and shared by every call, a classic surprise; give nothing, and Set the list inside the function.
A long condition can continue on the next line. Indent it further and start it with and or or:
When member is yes
and total is at least 100:
Give 20% of totalGive returns a value. Give back means the same. Call a function with <name> with <value> and <value>.
Records and rules#
A Customer has:
Name is text
Balance is money
Never allow a negative balance
Set ada to a Customer with name "Ada" and balance $10
Set ada's balance to ada's balance - $500
If this fails:
say "Not allowed: {error}"A Never allow rule is checked on every change. A change that breaks the rule fails, and the old value stays.
Records and calls written as blocks#
A record with many fields is easier to read as a block: end the line with : and give one field: value per line.
A Trade has:
Symbol is text
Quantity is whole number
Buy price is money
Sell price is money
Set first trade to a Trade:
symbol: "ACME"
quantity: 10
buy price: $20.00
sell price: $40.00It is the same program as Set first trade to a Trade with symbol "ACME" and quantity 10 and …. It works wherever a
record ends the line: Set … to a Trade:, Give a Trade:, Add a Trade to trades:, Expect a Trade to fail with "…":, and as the last value of a call (say calculate profit with a Trade:).
A function can be called the same way, with its inputs by name, in any order. An input with a default may be left out:
To taxed price:
Receive price and rate (7% if not given)
Give price + price * rate
Set total to taxed price:
price: $100
rate: 20%Names work only for a function whose inputs are known in the program (or in the project's src/). Each line must be
name: value; a name given twice, a field the record does not have, an input the function does not receive, or a
missing input that has no default is reported with its line and, when it is close, the name you probably meant
(TC113 to TC117, and TC206).
Tests#
Test "members spending at least 100 get 20% off":
Expect calculate discount with 150 and true to be 30
Expect counts at "c" otherwise 0 to be 0thunder test runs every Test block in the project and reports PASS or FAIL with the Thunder line.
Screens: build an app#
A Screen says what a person sees and what each button does. thunder run shows the first screen as an outline;
thunder build --target react writes it as a React app.
An Item has:
Name is text
Price is number
Screen Shop:
Remember cart as a list of Item, starting at []
Remember name as text, starting at ""
Remember price starting at 0
Show a heading "Shop"
Show a text box "Name" for name
Show a number box "Price" for price
Show a button "Add" (off when name is empty):
When pressed:
When price is at most 0:
Stop with "The price must be more than 0"
Add an Item with name name and price price to cart
Set name to ""
Show Cart:
items: cart
Screen Cart:
Receive items as a list of Item, title as text ("Your cart" if not given)
Show a heading: title
When items is empty:
Show "Your cart is empty"
Otherwise:
Show a list with each item in items:
Show a row:
Show item's name
Show item's price
Show a button "Back" that opens ShopA screen has three parts, in this order:
| Line | Meaning |
|---|---|
Receive items as a list of Item, title as text ("Your cart" if not given) |
what the screen that shows it gives it (its inputs), as in a function |
Remember coupon as text, starting at "" |
a value the screen keeps while it is shown, and where it starts |
Show … and When … : |
what it shows, from top to bottom |
What a screen can show:
| Line | Shows |
|---|---|
Show "Your cart is empty", Show "Total: {total}", Show item's name |
text (any value, written as in {…}) |
Show a heading "Shop", Show a heading: title |
a heading |
Show a list with each item in items: |
the lines under it, once for each item |
Show a row: |
the lines under it, side by side |
Show a text box "Coupon code" for coupon |
a box that changes a remembered text |
Show a number box "Price" for price |
a box that changes a remembered number |
Show a button "Add" (off when name is empty): then When pressed: and steps |
a button and what it does |
Show a button "Back" that opens Shop |
a button that opens another screen |
Show Cart: then items: cart (one input: value line each) |
another screen, inside this one, with its inputs |
When … :, Otherwise when … :, Otherwise: |
some lines only when a condition is yes |
What happens, exactly:
- A press changes everything or nothing. The steps under
When pressed:are ordinary Thunder steps (Set,Increase,Add … to,When,For each, calls,Stop with). They run on copies of the screen's remembered values. If every step works, the screen keeps the new values. If a step fails (orStop withstops it), nothing is kept and the screen says why, under what it shows:The price must be more than 0. - Typing sets the box's value. A number box keeps a number: text that is not one (or a decimal in a whole-number box) leaves the value as it was, and the screen says why.
- An off button does nothing when pressed.
- Opening a screen (
that opens Shop, or the stepOpen Shopafter other steps) shows it in place of this one. Its remembered values start again. A screen that is opened is given no inputs, so its inputs need defaults (TC214). - Inputs can't be changed by the screen that receives them, and neither can the items of a list it shows (TC213): remember a copy and change that.
- Each shown screen remembers its own values, by its place: two
Cardscreens in a list each have their own. A screen that stops being shown (itsWhenbecame no) forgets its values. - The first screen is where the app starts, so it needs no inputs.
Say,Give, andExpectcan't run when a button is pressed (TC407): a screen shows things instead.
thunder run prints the first screen as it first appears:
Screen "Shop"
Heading: Shop
Text box "Name": ""
Number box "Price": 0
Button "Add" (off)
Screen "Cart"
Heading: Your cart
Your cart is empty
Button "Back"Build it as a React app#
thunder build --target react writes generated/react/: <program>.tsx (one function component per screen, each
Remember a useState, each When pressed a function), main.tsx, index.html, thunder_runtime.mjs (the
Thunder engine's value and screen code, so the app means exactly what the engine means), thunder.css (calm defaults,
light and dark), package.json, and tsconfig.json. Run it with cd generated/react && npm install && npm run dev
(Vite), and check its types with npm run typecheck. Every line ends with its Thunder line, // thunder:N or
{/* thunder:N */}. A screen that can't be shown says why, with the line, as thunder run does.
The React app and the Thunder engine are checked against each other: for every screen program in the tests, React's
server-rendered HTML is read back and must be the engine's screen, and the same presses and typing must give the same
screen after every step (compiler/test/core-react.test.mjs). Screens build only for React: building a program with
screens for another target is refused with TC406, as is a React build of a program with no screen.
The Thunder style (thunder format)#
There is one way to write Thunder, and thunder format writes it. It should read well in plain text: in a terminal, a
diff, or on paper, with no colors.
Two spaces per level. No tabs, no trailing spaces, at most one blank line in a row.
Short stays short. A record built on one line keeps that line while it has 1 to 3 fields and fits in 100 columns. With 4 or more fields, or past 100 columns, it becomes a block of
field: valuelines.Long conditions wrap before
and/or, one part per line, indented two spaces:Thunder When member is yes and total is at least 100 and day is "Friday": Give 20% of totalSpace between ideas. One blank line around every function (
To), record (A … has), andTestblock. A comment right above one stays with it.One spelling for each thing.
When,Otherwise,Set,Give,Receive: Thunder keeps a small vocabulary on purpose, so every program reads the same way.
Formatting never changes what a program means: a block is the same program as the one-line form, and a wrapped condition is joined back into one line when it is read. Comments stay where they are, a program already in the Thunder style is left exactly as it is, and formatting twice gives the same text as formatting once. The tests format every Core program the examples, these docs, and the Core tests use, and check each gives the same program and the same output.
thunder format # print the formatted program
thunder format --write # save it
thunder format --check # exit 1 if a file is not in the Thunder style (for CI)Values#
| Kind | Written | Notes |
|---|---|---|
| whole number | 42 |
|
| number | 3.5 |
an exact decimal, never a binary float |
| money | $1.50 |
exact decimal amount |
| percent | 7%, 20% of total |
|
| text | "Total: {total}" |
{…} puts a value into text |
| yes/no | true / false (also yes / no) |
the kind is written yes/no or yes or no |
| nothing | nothing |
the absence of a value; test with is nothing |
| list | [1, 2, 3], an empty list |
positions start at 1: xs at 1 is the first item |
| map | an empty map |
counts at word; counts at word otherwise 0 gives a default |
| date | ||
| record | a Customer with name "Ada" and balance $10 |
Kinds can be named where needed: number, whole number, text, yes/no, money, date, list of …,
map of … to …, optional …, or a record name. Convert with as: "42" as whole number,
row's amount as money, rows as list.
Expressions#
- Arithmetic:
+ - * /andmod, or in words:plus,minus,times,divided by. - Comparisons:
is,is not,is at least,is at most,is more than,is less than,is between 1 and 10,is in,contains,does not contain,is empty,is positive,is negative,is zero,is nothing. - Logic:
and,or,not. - Built-ins written
the <op> of <value>:sum(total),average,count,smallest,largest,length,first,last,words,lines,lowercase,uppercase,trimmed,keys,values. - From a list of records:
prices from orders,orders where paid is true,orders sorted by price descending. round xandround x to 2 places;read file "orders.csv".
Text, lists, and JSON#
| Write | Gives | Example |
|---|---|---|
names joined with ", " |
text | ["Ada", "Grace"] → "Ada, Grace" (every item must be text) |
line split at "," |
list of text | "a,,b" → ["a", "", "b"] (empty parts are kept) |
the parts of text |
list of text | " the cat. sat " → ["the", "cat.", "sat"] (split at spaces; punctuation kept) |
date replacing "-" with "/" |
text | "2026-11-25" → "2026/11/25" (every match) |
name starts with "Dr", file ends with ".csv" |
yes/no | |
scores sorted, scores sorted descending |
list | the values themselves, smallest first |
the absolute value of x |
number or money | -2.5 → 2.5; -$4.10 → $4.10 |
the largest of [a, b], the smallest of [a, b] |
the item | |
the JSON data in text |
lists, maps, text, yes/no, nothing, numbers | numbers are exact: 0.1 read from JSON plus 0.2 is 0.3 |
the JSON text of value |
text | written like Python's json.dumps, with numbers as they are held (2.50 stays 2.50) |
Each one checks the kinds it works on. When a kind is known in advance, the checker reports the problem before
running: [1, 2] joined with ", " is an error. When it is not, the program stops while running with a message in
words, for example "joined with" joins text, but item 1 is the number 1. Invalid JSON stops with TC509. Money has
no JSON form of its own: write its amount.
the words of splits text at spaces and removes punctuation at either end of each word, so "dog." is
dog. An apostrophe inside a word stays (don't).
These words belong to Thunder and cannot be part of a name: is are and or not to at of with from where by in as than the a an plus minus times divided mod true false yes no nothing otherwise sorted descending ascending equals contains between joined split replacing starts ends. A yes/no function therefore cannot be called is adult. Write check adult.
What a value means (the same in every target)#
- Division is exact.
7 / 2is3.5, never3.0.1 + 0.2is0.3. - Money is exact. Money adds to money and multiplies or divides by plain numbers.
$5 + 1is an error (write$1).$2 * $3is an error. An average of money keeps every digit; round it to show cents. - Rounding is half up:
round 2.5is3, andround $2.345 to 2 placesis$2.35. - Positions start at 1.
- Nothing is not zero, not empty, and not false. Using
nothingwhere a value is needed is an error. The checker reports it when it can tell in advance (TC305). Otherwise the program reports it while running (TC502). - Yes/no is explicit. Write
member is true. Each language treats other values as true or false differently, so Thunder does not. When a value's kind is not known in advance (an input, a value from Python), a condition,and,or,not, or a comparison withtrue/falsechecks it while running:1or"yes"stops with "This needs a yes/no value, but it is the number 1", never quietly counted as true or false. - A Python float is the exact number it is written as. A float that reaches Thunder (an input, a field of a
Python object) becomes the exact decimal
19.99, never19.989999999999998, before any arithmetic or comparison. - Nothing is silently changed. If code cannot do what it says, it fails with a message in words. Thunder never substitutes a different behavior.
Problems and failures#
The checker reports problems before anything runs, each with a line and a stable code:
main.thunder, line 1: I don't know what "xs" is.
Set it first (Set … to …), receive it, or check the spelling. [TC201]While running, a failure names the Thunder line, and the lines that led to it:
main.thunder, line 3 (reached from line 6): You divided by zero. [TC501]| Codes | Meaning |
|---|---|
| TC1xx | the line does not fit the grammar (indentation, missing words) |
| TC113–TC117 | a record or a call written as a block: a line that is not name: value, a name given twice, an unknown or missing input, or no record or call to give the lines to |
| TC2xx | names: unknown names, fields, records |
| TC3xx | kinds of values that cannot do what the line asks |
| TC4xx | where a statement is allowed (functions, records, Use, and tests at the left edge) |
| TC405 | a Python module (Use) in a program compiled to a language other than Python |
| TC118, TC119 | a line in a Screen that a screen can't show, or Receive / Remember below what it shows |
| TC212–TC214 | screens: an unknown screen, an input changed by the screen that receives it, an input missing or unknown |
| TC406, TC407 | screens built for a target other than React (or React with no screen), and a step that can't run on a press |
| TC501 | divided by zero |
| TC502 | nothing used where a value was needed |
| TC503 | a missing map entry or list position |
| TC506 | values of different kinds mixed while running |
| TC507 | Stop with |
| TC508 | Python code used through Use failed (Python code used by this line failed: …) |
Python libraries#
Use <module> as <name> gives a program the Python ecosystem. Thunder uses those libraries. It does not
rebuild them.
Use csv as csv
Set rows to csv.DictReader(the lines of text) as list
For each row in rows:
say "{row's name}: {row's amount as money}"Code reached through Use is Python. Thunder's rules (exact money, positions from 1) apply to Thunder values,
not inside the library. A failure inside the library is reported against the Thunder line that called it (TC508).
Step through a run: the Time Machine#
Record a run, then step forward and back through it, one statement at a time, with the real values:
thunder run shop --record run.json # runs it on the Thunder engine and saves every step
thunder replay run.json # Enter or n: next · b: back · j 7: jump · q: quit
thunder replay run.json --step 3 # one step
thunder replay run.json --json # the whole recording, as data⏱ Step 3 of 6 · src/main.thunder, line 10 · in the program
Set fee to delivery fee with total
Calls "delivery fee" (steps 4–5), then:
fee: → $0.00
⏱ Step 4 of 6 · src/main.thunder, line 3 · inside "delivery fee"
When total is at least $20:
→ yesEach step shows the line, which values changed (before → after, as the program would print them), what it printed,
what a function gave back, and for a choice which way it went ("yes", or "no, so the Otherwise steps"). A recording is
made on the Thunder engine, so programs that use a Python module (Use) cannot be recorded. It replays what happened:
going back shows an earlier moment and never undoes anything the program did. A recording stops growing after 20,000
steps (and says so); the program still runs to the end. The format is thunder-time-machine-v1.
Run without Python: the Thunder engine#
thunder run --engine thunder # run the program on the Thunder engine: no Python needed
thunder test --engine thunder # run every Test block the same wayThe Thunder engine runs the same checked program the Python compiler uses, so a program means the same thing on both: the same output, the same errors (code, words, line, and "reached from"), and the same exit status. Every program in Thunder's Core tests runs on both engines, and the results must match, or the tests fail.
- Python stays the default and the production backend:
thunder runandthunder buildstill compile to Python, and the generated Python runs without Thunder. - A program that uses a Python module is refused on the Thunder engine, with the module and the line, before
anything runs. Thunder never imitates a library:
Use csv as csvmeans Python'scsv, so that program runs with Python. - Calls can go as deep as on Python (about a thousand), and a program that goes deeper stops at the same call with the same message.
Compile to TypeScript#
The same program, compiled to TypeScript and run on Node:
thunder build --target typescript # generated/typescript/: one .ts per file, the runtime, its types, tsconfig.json
thunder run --target typescript # run the compiled TypeScript
thunder test --target typescript # run every Test block as TypeScriptOr set it for the project in thunder.toml: target = "typescript" under [build] (output goes to
generated/typescript unless output says otherwise).
- The same meaning. Every Core test program runs three ways: compiled to Python, on the Thunder engine, and
compiled to TypeScript. The output, every error (its code, its words, its line, and "reached from"), and the exit
status must be the same, or the tests fail. The runtime written next to the TypeScript (
thunder_runtime.mjs) is the Thunder engine's own value code, so exact numbers, money rounded half up, positions from 1, and yes/no checks are not reimplemented a third time. - Readable, typed, erasable. Plain exported functions, records, and kept values; every line ends with
// thunder:N. The code uses only types Node can strip, andtsc --strictaccepts it (tsc -p generated/typescript). Values whose kind Thunder checks while running are typedany. - How it runs. Node 23.6 and newer run TypeScript directly; Node 22.6 needs
--experimental-strip-types, which Thunder adds. On an older Node, Thunder removes the types with thetypescriptpackage if it can find it (in the project or next to Thunder); otherwise it says what to install.thunder buildneeds neither. - No Python modules. A program that uses
Use csv as csvis refused for this target before anything is written (TC405): Python modules exist only for Python, and Thunder never swaps in a different library. npm libraries are not available from Thunder yet.
Compile to C##
The same program, compiled to C# and run on .NET (8 or newer):
thunder build --target csharp # generated/csharp/: one .cs per file, ThunderRuntime.cs, Program.cs, ThunderProgram.csproj
thunder run --target csharp # build it with dotnet and run it
thunder test --target csharp # run every Test block as C#Or set it for the project in thunder.toml: target = "csharp" under [build]. The output is an ordinary console
project: dotnet run --project generated/csharp runs it without Thunder (-- test runs the tests).
- The same meaning. Every Core test program also runs compiled to C#, and the output, every error (its code, its
words, its line, and "reached from"), and the exit status must be the same as on Python, the Thunder engine, and
TypeScript, or the tests fail.
ThunderRuntime.cs(base class library only) is a line-by-line port of the engine's value code: exact decimals onBigInteger(not .NET's 28-digitdecimal), money rounded half up, positions from 1, strict yes/no, and the same words for every error. - Readable. One static class per Thunder file, a static method per function (an input with a default gets an
overload), records with their Never rules, and every line ends with
// thunder:N. Values whose kind Thunder checks while running areobject. - How it runs.
thunder runandthunder testbuild with the .NET SDK (dotnet build) and run the result. Without the SDK, Thunder says what to install (exit 2);thunder buildstill writes the C#. Programs run on a thread with a deep stack, so calls nest as deep as they can in Python. - No Python modules. A program that uses
Use csv as csvis refused for this target before anything is written (TC405). NuGet libraries are not available from Thunder yet.
Compile to Rust#
The same program, compiled to Rust:
thunder build --target rust # generated/rust/: one .rs per file, main.rs, thunder_runtime.rs, Cargo.toml
thunder run --target rust # build it with cargo (offline) and run it
thunder test --target rust # run every Test block as RustOr set it for the project in thunder.toml: target = "rust" under [build] (output goes to generated/rust
unless output says otherwise). The output is an ordinary Cargo project: cargo run --offline --manifest-path generated/rust/Cargo.toml runs it without Thunder (-- --tests runs the tests).
- The same meaning. Every Core test program runs on Python, the Thunder engine, compiled TypeScript, and compiled
Rust; the output, every error (its code, its words, its line, and "reached from"), and the exit status must be the
same, or the tests fail.
thunder_runtime.rsis a line-by-line port of the Thunder engine's value code: exact decimals of any size, money rounded half up, positions from 1, strict yes/no, the same text for every value and every error. - No dependencies. The runtime uses only Rust's standard library (its exact numbers are written in it), so the program builds offline. Calls can go as deep as on Python (about a thousand): the program runs on a thread with a deep stack and stops at the same call, with the same message, when it goes deeper.
- Readable. Plain functions that take and give
Values, records with their Never rules, kept values, and tests; every line ends with// thunder:N. An error is carried up to the nearest Thunder call, which notes the line. - How it runs.
thunder runandthunder testneed the Rust toolchain (rustcandcargo, from https://rustup.rs); without it Thunder says what to install.thunder buildneeds neither. - No Python modules. A program that uses
Use csv as csvis refused for this target before anything is written (TC405). Crates are not available from Thunder yet.
Compile to Go#
The same program, compiled to Go and built with the go toolchain:
thunder build --target go # generated/go/: one .go per file, go.mod, and the runtime in thunder/
thunder run --target go # build and run the compiled Go
thunder test --target go # run every Test block as GoOr set it for the project in thunder.toml: target = "go" under [build] (output goes to generated/go unless
output says otherwise). The output is an ordinary Go module: cd generated/go && go run . runs the program without
Thunder, and go run -tags thundertests . runs its tests.
- The same meaning. Every Core test program runs four ways: compiled to Python, on the Thunder engine, compiled to
TypeScript, and compiled to Go. The output, every error (its code, its words, its line, and "reached from"), and the
exit status must be the same, or the tests fail. The runtime (
thunder/thunder_runtime.go) is a port of the Thunder engine's value code: exact decimals (math/big), money rounded half up, positions from 1, strict yes/no, and the same messages. - Readable Go, standard library only. Plain functions in one
mainpackage, records, and kept values; every statement ends with// thunder:N. Values whose kind Thunder checks while running have the typeT.V. A Thunder error is a Go panic that each function's frame annotates on the way out, so the error names the Thunder line and the calls that reached it. Nothing is downloaded: the module has no dependencies. - How it runs. Go 1.21 or newer (
goon the PATH, orTHUNDER_GO).thunder build --target goworks without it. - No Python modules. A program that uses
Use csv as csvis refused for this target before anything is written (TC405). Go packages are not available from Thunder yet.
Compile to Java#
The same program, compiled to Java (17 or newer) and run on the JVM:
thunder build --target java # generated/java/: app/<Class>.java per file, app/RunTests.java, the runtime in thunder/
thunder run --target java # compile with javac and run
thunder test --target java # run every Test block as JavaOr set it for the project in thunder.toml: target = "java" under [build].
- The same meaning. Every Core test program runs four ways: compiled to Python, on the Thunder engine, compiled to
TypeScript, and compiled to Java. The output, every error (its code, its words, its line, and "reached from"), and
the exit status must be the same, or the tests fail. The Java runtime (
thunder/ThunderRuntime.java, JDK only) follows the Thunder engine's value code line for line: exact decimals as Python'sDecimal, money rounded half up, positions from 1, strict yes/no, and the same messages. - Readable. One class per Thunder file (
main.thunderisapp.Main), with a static method per function, records, and kept values; every line ends with// thunder:N. Calls go as deep as on Python: the program runs on a thread with a deep stack, and a program that goes deeper stops at the same call with the same message. - How it runs. Thunder finds the JDK through
THUNDER_JAVA_HOME,JAVA_HOME, or the PATH; without one it says what to install.thunder buildneeds no JDK. The built program runs without Thunder:javacthe files inapp/andthunder/, thenjava -cp classes app.Main. - No Python modules. A program that uses
Use csv as csvis refused for this target too (TC405). Maven libraries are not available from Thunder yet; Thunder never swaps in a different library.
What the generated Python looks like#
Every generated line ends with # thunder:N, the Thunder line it came from. thunder_runtime.py is written next
to it. It uses only the standard library and implements the rules in "What a value means". The generated program
runs without Thunder installed.
Reading and writing are the same language: read Python as Core#
thunder read shop.py --as-core # the same code as Thunder Core you can edit, compile, and run
thunder read shop.py --as-core --json # plus, per function: exact or not, each line not translated and why shop.py ──reader──▶ meaning tree ──--as-core──▶ Thunder Core ──compile──▶ Python ──run next to shop.py──▶ same?The Core is printed from the reader's meaning tree, never from its English sentences, so each line means what the code means:
def total_paid(orders): To total paid:
total = 0 Receive orders
for o in orders: Set total to 0
if o.paid: For each o in orders:
total += o.price When o's paid is true:
return total Increase total by o's price
Give totalNever a guess. A line Core cannot say with the same meaning is not rewritten into something close. It is marked, and it becomes a line that stops if it runs:
To with_tax:
Receive orders
# Not translated (line 11): Python round() rounds halves to even; Thunder rounds half up
Stop with "Line 11 of the Python was not translated: return round(total_paid(orders) * (1 + TAX), 2)"A function with such a line is not safe to edit. --as-core says so on stderr, and --json gives
exact: false with each line and its reason. Today it refuses these, among others:
split(sep, maxsplit),replace(a, b, count),startswith((…))with a tuple, andmax(…, key=…).round(): it rounds halves to even.//: floor division.try/exceptthat names its error kinds.- List positions it cannot tell from map keys.
- Bytes.
- Tuples outside
in. - Decorators.
- A function passed as a value: in Core, writing a function's name calls it.
- Special methods (
__len__,__eq__,__repr__, …), inner functions, and methods of nested classes.
Methods. A method of a class becomes a Core function that receives the object first. Core has functions and records, not methods:
class Account: To Account withdraw:
def withdraw(self, amount): Receive self and amount
if not self.can_withdraw(amount): When not ((Account can withdraw with self and amount) is true):
raise ValueError("insufficient") Stop with "insufficient"
self.balance -= amount Set self's balance to self's balance - amountself.can_withdraw(x) is printed as Account's own can withdraw. That is written down as an assumption: Python
picks the method when it runs, so a subclass could replace it. A static method is printed as a plain function.
__init__ is printed as <Class> set up. A self.other() that this class does not define (it may come from a
parent class) is not translated.
Assumptions are written down, never hidden. Python if member: is printed as member is true. The compiled
Core checks that member really is yes/no when it runs (rule 6 above). xs[0] is printed as xs at 1, and the
output notes that it reads xs as a list.
The output always compiles. A function whose printed Core would not compile is shown as comments under one
Stop with line, and it is reported as not translated.
Checked by running. core-read-write.md prints 20 small Python functions as Core,
compiles each one, and runs it next to the original on sample inputs. It compares the value given back, what was
printed, and any error. The page also measures how far the reader's English (Thunder Text) is from Core.
Python is the only source language for --as-core so far.
Use Thunder Core from your own code#
@skillstech/thunderlang/program is the public, browser-safe library entry (no Node needed):
import { compileCore, runInProcess, toPython, screenApp, screenOutline } from "@skillstech/thunderlang/program";
const result = compileCore('say "Hello"\n', { file: "main.thunder" });
if (result.ok) {
runInProcess({ entry: result, cwd: "." }).stdout; // "Hello\n"
toPython(result.program, result.info, { source: "main.thunder" }); // the generated Python
}It also has toTypeScript, toCSharp, toJava, toGo (with goNamespaces), toRust, toReact, recordedRun (the
Time Machine), testInProcess, and pythonToCore. Files a program reads come only from the readText you pass.
Examples#
examples/core/ holds the demo programs: hello, discount, savings, word-count, csv-summary, and
trading-journal. Run them with thunder run examples/core/<file>.thunder, and test them with
thunder test examples/core.