Skip to main content
ThunderLang™
Draft documentation. Syntax and behavior are illustrative and will change before v1.

What Thunder means: the rules, and the tests that check them

A Thunder™ program means the same thing on every engine and target: Python, the Thunder engine, TypeScript, C#, Rust, Go, and Java. This page writes down what that meaning is, topic by topic, and names the tests that check each rule.

How the rules are checked. Every test named below runs its program on every engine and target and requires the same output, the same error, and the same exit status from all of them (runBoth in compiler/test/core-engines.mjs; C# is built in one batch at the end of each file). A target whose toolchain is not installed is left out of that run, and CI installs them. Test files are in compiler/test/; "both engines agree: …" tests are in core-engine.test.mjs. This page is part of the 2.0 language specification.

1. Decimals#

  • A number with a decimal point is an exact decimal, never a binary float: 0.1 + 0.2 is 0.3.
  • A result keeps 28 significant digits. A longer one is rounded to 28 digits, half to even: 1 / 3 is 0.3333333333333333333333333333. Very small and very large decimals stay exact: 1 divided by 10 forty times is 0.0000000000000000000000000000000000000001.
  • A whole number and a decimal mix exactly. 1 is 1.0 is yes, and 1 and 1.0 are the same key in a map.
  • Showing a decimal drops trailing zeros (say 2.50 shows 2.5); JSON text keeps the digits as held (2.50).
  • A Python float that reaches Thunder (an input, a field of a Python object) becomes the exact decimal it is written as (19.99, never 19.989999999999998). This only happens on Python, the one target with Python objects.
Checked by
core-run.test.mjs "decimal numbers are exact: 0.10 + 0.20 is 0.3"; "a whole number written with leading zeros…"
core-engine.test.mjs both engines agree: "exact decimals: long division, trailing zeros, negative zero"; "comparisons across kinds of numbers"; "maps: … 1 and 1.0 are one key"
core-stdlib.test.mjs "JSON: numbers are read exactly…"
core-meaning.test.mjs "decimals keep 28 significant digits; tiny and huge decimals stay exact"

2. Division#

  • Division is exact and never cut to a whole number: 7 / 2 is 3.5.
  • Money divided by a number is money; money divided by money is a plain number. A plain number divided by money stops with "A plain number can't be divided by money." (TC506).
  • Dividing by zero, with /, mod, or money, stops with "You divided by zero." (TC501).
Checked by
core-run.test.mjs "division is exact and never cut to a whole number"; "a runtime error is reported against the Thunder line…"
core-engine.test.mjs both engines agree: "dividing money by money and numbers by money"; "money: display keeps the cents…"
core-meaning.test.mjs "If this fails catches a failure; the statements before it have already happened"

3. Rounding and remainders#

  • round goes half away from zero: round 2.5 is 3, round -2.5 is -3, round $2.345 to 2 places is $2.35, round -$2.345 to 2 places is -$2.35. Rounding money gives money; round x with no places gives a whole number.
  • mod has the sign of the divisor: -7 mod 3 is 2, 7 mod -3 is -2.
  • The only other rounding is the 28-digit limit in section 1 (half to even), which happens inside a calculation and never changes a result that fits.
Checked by
core-run.test.mjs "rounding goes half away from zero; mod has the sign of the divisor"
core-engine.test.mjs both engines agree: "rounding and remainders"; "sums, averages and extremes of money"
core-meaning.test.mjs "rounding goes half away from zero, for numbers and money alike"

4. Text#

  • Positions start at 1, for lists and the items of text split into parts. A missing position says how many items there are: "There is no item 3: the list has 1 item." (TC503). A position that is not whole is TC506.
  • The length of text counts Unicode code points: "héllo" is 5, "👍🏽" is 2 (a thumb and a skin tone).
  • Text is compared and sorted by Unicode code point, not by the rules of any language: "Ab" < "ab", "é" comes after "z", and "10" < "9".
  • uppercase and lowercase follow Unicode as Python and JavaScript do: straße becomes STRASSE, a Greek Σ at the end of a word becomes ς, and İ becomes i̇.
  • Putting a value inside text ("total {x}") shows it in Thunder's words: yes/no, nothing, lists.
  • Turning text into a number checks it: "abc" as number stops with the text "abc" is not a number. (TC509).
Checked by
core-run.test.mjs "text interpolation, words, and maps"; "positions start at 1, and a missing one is explained"; "conversions: text to numbers…"
core-stdlib.test.mjs "text: joined with, split at…"; "kinds are checked…"
core-engine.test.mjs both engines agree: "text: interpolation of every kind, words, lines, case, trimming"; "positions that are not there"; "a position that is not a whole number"; "conversions and their errors"
core-meaning.test.mjs "text: length counts code points; comparing and sorting follow code points, not a language"; "uppercase and lowercase follow Unicode as Python and JavaScript do"

5. Nothing#

  • nothing is a value of its own: not zero, not empty, not false. It shows as nothing and is tested with is nothing; nothing is nothing is yes, and nothing equals any other value.
  • Using nothing where a value is needed (arithmetic, ordering, between) is an error. The checker reports it when it can tell in advance (TC305); otherwise the program stops while running with "A value was nothing where a value was needed." (TC502).
  • An optional field left out of a record is nothing; a list or map field left out is empty.
Checked by
core-run.test.mjs "nothing: shown as "nothing"…"; "using nothing where a value is needed…"
core-engine.test.mjs both engines agree: "nothing where a value is needed"; "optional fields and lists left out of a record"
core-meaning.test.mjs "nothing cannot be ordered: comparing it with a number stops with TC502"

6. Changing values, and Never rules#

  • Lists, maps, and records are shared, not copied. Set b to a gives the same list or record a second name: a change through either name is seen through both, and a function that changes a list it received changes the caller's list.
  • Add, Remove, Sort, and Reverse change a list where it is. Removing something that is not there is an error.
  • A Never rule is checked on every change, before the change is kept. A change that breaks it stops with <the rule> (the rule on line N), but the value is <the value>. (TC504), and the old value stays. This holds for a name, a record's field, and a list a rule watches: a watched list is changed on a copy, checked, then kept, so a refused Add or Remove leaves the list as it was. (Other names that shared the old list keep the old list.)
  • Making a record checks its rules on the fields it is made with.
  • Which alternative an either/or value is cannot be changed.
Checked by
core-run.test.mjs "Never: a broken rule stops the change, and the old value stays"; "Never: making a record that breaks a rule fails at the line that made it"
core-engine.test.mjs both engines agree: "records: fields, changes, … Never rules on fields"; "a Never rule on a value that changes"; "lists: positions from 1, sorting…"; "removing what is not there"
core-meaning.test.mjs "lists and records are shared, not copied"; "a list a Never rule watches: a change that breaks the rule is refused, and the old list stays"
core-alternatives.test.mjs "which alternative a value is cannot be changed" (checked before running)

7. Errors#

  • A problem while running is reported as <file>, line N (reached from line A, then line B): <words> [TCxxx], and the program ends with status 1. Stop with "…" is TC507.
  • If this fails: protects the one statement before it. Under it, error is the problem in words, without the code. What happened before the failure is not undone.
  • A function that calls itself more than 997 levels deep stops with "A function called itself too many times."
  • Nothing is silently changed. When code cannot do what it says, it fails with a message in words; Thunder never substitutes a different behaviour.
Checked by
core-run.test.mjs "If this fails: the error message is in words"; "Stop with a message ends the program…"; "money and a plain number mixed at runtime…"; "Test blocks: passing and failing Expect lines…"
core-engine.test.mjs both engines agree: "Stop inside a function, reached from two levels up"; "If this fails catches Stop and keeps going"; "recursion past the limit stops at the same call"; "mixing kinds that the checker cannot see"; "a yes/no that is not one"
core-meaning.test.mjs "If this fails catches a failure; the statements before it have already happened"

8. Overflow, large numbers, and money#

  • Whole numbers have no limit on any target: there is no overflow at 32 or 64 bits. 2 * 9223372036854775807 is 18446744073709551614, and 25 factorial is 15511210043330985984000000.
  • Money is an exact decimal. It shows at least two places and keeps any extra digits it holds (an average of money shows every digit; round it to show cents). Thousands are grouped with commas; a negative amount shows as -$40.00.
  • Money adds only to money (a plain 0 is the one exception): $5 + 1 stops with TC506, and $2 * $3 stops with "Money can't be multiplied by money."
Checked by
core-run.test.mjs "money is exact: $0.10 + $0.20 is $0.30"; "lists: sum, average…"
core-engine.test.mjs both engines agree: "money: display keeps the cents it has…"; "money times money"; "money compared with a plain number"
core-meaning.test.mjs "whole numbers have no limit: past 64 bits, factorials, and remainders stay exact"

9. Effects#

  • say writes a line to standard output; every test above checks it.
  • read file "…" reads a file relative to the folder the program runs in.
  • today is the local date. Dates written in a program are checked (date "2023-02-29" is not a date). There is no time of day.
  • Stored lists (Store … as a list of …) are kept in data/<name>.json, in one format on every engine that has them. Only a program that finishes saves; one that stops with a problem saves nothing; tests start empty and never save. Stored lists run on Python, the Thunder engine, TypeScript, and Go; C#, Java, and Rust refuse them (TC410).
  • HTTP (When someone calls …, the answer from GET "…") runs on Python, the Thunder engine, and TypeScript, with the same answers on each; the other targets refuse it (TC411).
  • Python modules (Use) run only on Python, and npm packages only on TypeScript; every other engine refuses them (TC405, TC408). These are the only intended differences between targets.
Checked by
core-engine.test.mjs "the example programs and their tests (examples/core) agree on both engines" (reads a file); both engines agree: "dates"
core-store.test.mjs "a damaged file says where and what is wrong, the same on every engine"; "Python, compiled TypeScript, and the Thunder engine read and write the same file"; "compiled Go takes turns on the same file, byte for byte"; "a program that stops with a problem saves nothing"; "every other target refuses a stored list (TC410)"
core-http.test.mjs "tests call endpoints directly, the same on every engine"; "calling another service: … failures in words"; "every other target refuses endpoints and calls to other services (TC411)"

Not covered by a cross-target test yet#

Written down so nobody mistakes them for checked behaviour:

  • A decimal with an exponent beyond about ±999,999 (Python's limit; the other engines have none).
  • today (its value changes, so it is checked only on each engine alone).
  • The messages for a missing file or folder in read file.
  • A stored list that stops with a problem, on Python (checked on the Thunder engine).