Skip to main content
ThunderLang™

Compiler

Thunder to Python compiler

Write a program in Thunder, the human programming language, and get Python. The same program gives the same output in all six languages Thunder compiles to.

✓ Thunder understands this program.

Type or paste your own. It converts as you type, in your browser: nothing is sent anywhere.

In Python

# Generated by the Thunder compiler from main.thunder.
# This file is a build artifact: change main.thunder and build again, or keep this file and edit it as Python.
# It needs only Python 3.10+ and thunder_runtime.py (written next to it). "# thunder:N" marks the Thunder line.

from decimal import Decimal
from thunder_runtime import Stop, num, run, show, yes_no

THUNDER_SOURCE = "main.thunder"


def shipping_cost(weight, express):  # thunder:1
    if num(weight) <= 0:  # thunder:3
        raise Stop("weight must be positive")  # thunder:4
    cost = 5 + num(num(weight) * 2)  # thunder:5
    if yes_no(express) is True:  # thunder:6
        cost = num(cost) * Decimal("1.5")  # thunder:7
    return cost  # thunder:8


def grade(score):  # thunder:10
    if num(score) >= 90:  # thunder:12
        return "A"  # thunder:13
    elif num(score) >= 80:  # thunder:14
        return "B"  # thunder:15
    elif num(score) >= 70:  # thunder:16
        return "C"  # thunder:17
    return "F"  # thunder:18


def main():
    print(show(shipping_cost(3, False)))  # thunder:20
    print(grade(85))  # thunder:21


if __name__ == "__main__":
    run(main, __file__)

What you get

  • Python that runs and gives the same results as every other language Thunder compiles to: exact decimals, the same errors, the same output. The same test programs check every target.
  • Generated code, not hand-written style. Values are dynamic, and the code uses a small Thunder runtime file that thunder build writes next to it. It runs, and you can keep and edit it, but it won't read like Python a person would write.
  • Each line ends with a mark showing the Thunder line it came from, so you can trace any line back.

What compiles today

  • Thunder Core programs: functions, decisions, lists, records, either/or data, saved data, tests, and more. Thunder Core guide.
  • Some features work on some targets only (for example, HTTP endpoints on Python, TypeScript, and the Thunder engine). When a program can't be written in Python, the converter says so instead of writing something different.

The example, step by step

Written by the Thunder compiler 2.0.0 while this page was built, not by hand.

Thunder

To shipping cost:
  Receive weight and express
  When weight is at most 0:
    Stop with "weight must be positive"
  Set cost to 5 + weight * 2
  When express is true:
    Set cost to cost * 1.5
  Give cost

To grade:
  Receive score
  When score is at least 90:
    Give "A"
  Otherwise when score is at least 80:
    Give "B"
  Otherwise when score is at least 70:
    Give "C"
  Give "F"

say shipping cost with 3 and false
say grade with 85

Python

# Generated by the Thunder compiler from main.thunder.
# This file is a build artifact: change main.thunder and build again, or keep this file and edit it as Python.
# It needs only Python 3.10+ and thunder_runtime.py (written next to it). "# thunder:N" marks the Thunder line.

from decimal import Decimal
from thunder_runtime import Stop, num, run, show, yes_no

THUNDER_SOURCE = "main.thunder"


def shipping_cost(weight, express):  # thunder:1
    if num(weight) <= 0:  # thunder:3
        raise Stop("weight must be positive")  # thunder:4
    cost = 5 + num(num(weight) * 2)  # thunder:5
    if yes_no(express) is True:  # thunder:6
        cost = num(cost) * Decimal("1.5")  # thunder:7
    return cost  # thunder:8


def grade(score):  # thunder:10
    if num(score) >= 90:  # thunder:12
        return "A"  # thunder:13
    elif num(score) >= 80:  # thunder:14
        return "B"  # thunder:15
    elif num(score) >= 70:  # thunder:16
        return "C"  # thunder:17
    return "F"  # thunder:18


def main():
    print(show(shipping_cost(3, False)))  # thunder:20
    print(grade(85))  # thunder:21


if __name__ == "__main__":
    run(main, __file__)

On your computer

The same conversion with the thunder command (Node.js 18+). Nothing is sent anywhere, and no AI is involved.

npm install -g @skillstech/thunderlang
thunder build shipping.thunder --core   # writes generated/python/