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

Read ↔ write: how close is the reader's Thunder Text to Thunder Core?

Generated by node compiler/scripts/core-read-write.mjs. Do not edit by hand; run the script again.

Thunder's rule is that reading and writing are the same language: code Thunder reads should come out as Thunder Core a person can edit and compile back. This page measures that on 20 small Python functions.

Printed as Core from the meaning tree (thunder read <file.py> --as-core)#

The reader parses Python into a meaning tree. --as-core prints that tree as Thunder Core, never from the English sentences, so each line means what the code means. A line Core cannot say with the same meaning is not rewritten into something close: it is marked not translated and becomes a Stop with "…" line, so running it fails loudly instead of skipping it, and the function is not safe to edit. Then the Core is compiled to Python and run next to the ORIGINAL function on the sample inputs, comparing the value given back, what is printed, and errors.

Measure Result
Printed Core that compiles 20 of 20
Printed exactly: no line marked not translated 19 of 20

| Exactly printed functions that give the same results as the original Python on every sample input | 19 of 19 (53 of 53 inputs) |

Not translated, and why (each is a meaning Core cannot say yet, so Thunder refuses rather than guesses):

  • safe_divide, line 2: Core has no step for a Python try (an error handler that names its error kinds) yet.

Assumptions written next to the Core (kept only for some inputs, never hidden): a Python value used as a condition (if member:) is printed as member is true, and the compiled Core stops with an error if the value is not yes/no, where Python would quietly treat 1, "x", or a non-empty list as true.

Methods#

A method is printed as a Core function that receives the object first (Core has functions and records, not methods): Account.deposit(self, amount) becomes To Account deposit: with Receive self and amount, and self.can_withdraw(x) becomes Account can withdraw with self and x (written down as an assumption: a subclass could replace it). Special methods such as __len__ change how Python treats the object and are not translated. Each method is run next to the original, and the object afterwards is compared too.

Class Methods printed exactly Same results as the original (object afterwards included)
Account 6 of 6 6 of 6 methods, 12 of 12 inputs (1 within 1e-9: Python float, Core exact)
Cart 4 of 5 (not: __len__) 4 of 4 methods, 7 of 7 inputs

Account#

Python
class Account:
    rate = 0.02

    def __init__(self, owner, balance):
        self.owner = owner
        self.balance = balance

    def deposit(self, amount):
        if amount <= 0:
            raise ValueError("amount must be positive")
        self.balance += amount
        return self.balance

    def can_withdraw(self, amount):
        return amount <= self.balance

    def withdraw(self, amount):
        if not self.can_withdraw(amount):
            raise ValueError("insufficient")
        self.balance -= amount

    def interest(self):
        return self.balance * self.rate

    @staticmethod
    def fee(amount):
        return amount * 0.01

Printed as Core:

Output
To Account set up:
  Receive self, owner and balance
  Set self's owner to owner
  Set self's balance to balance

To Account deposit:
  Receive self and amount
  When amount is at most 0:
    Stop with "amount must be positive"
  Set self's balance to self's balance + amount
  Give self's balance

To Account can withdraw:
  Receive self and amount
  Give amount is at most self's balance

To Account withdraw:
  Receive self and amount
  When not ((Account can withdraw with self and amount) is true):
    Stop with "insufficient"
  Set self's balance to self's balance - amount

To Account interest:
  Receive self
  Give self's balance * self's rate

To Account fee:
  Receive amount
  Give amount * 0.01
  • withdraw assumes: self.can_withdraw() is read as Account's own can_withdraw; a subclass that replaces it would run its own version.
  • withdraw assumes: Account can withdraw with self and amount is read as yes/no (Python would also accept other values here); Core stops with an error if it is not yes/no.

Cart#

Python
class Cart:
    def __init__(self):
        self.items = []

    def add(self, item):
        self.items.append(item)

    def total(self):
        total = 0
        for item in self.items:
            total += item.price
        return total

    def is_empty(self):
        return len(self.items) == 0

    def __len__(self):
        return len(self.items)

Printed as Core:

Output
To Cart set up:
  Receive self
  Set self's items to []

To Cart add:
  Receive self and item
  Add item to self's items

To Cart total:
  Receive self
  Set total to 0
  For each item in self's items:
    Increase total by item's price
  Give total

To Cart_is_empty:
  Receive self
  Give (the count of self's items) is 0

To Cart_len:
  Receive self
  # Not translated (line 17): __len__ is a special method: it changes how Python treats the object (operators, printing, comparing), which Core cannot say
  Stop with "__len__ was not translated from Python: __len__ is a special method: it changes how Python treats the object (operators, printing, comparing), which Core cannot say"
  • __len__ not translated: len is a special method: it changes how Python treats the object (operators, printing, comparing), which Core cannot say.

The reader's English (Thunder Text)#

Thunder Text describes code for people ("Sets total to 0"); it is not meant to compile. These numbers show how far its sentences are from Core statements.

Measure Result
Reader's text compiles as Core, unchanged (whole function) 0 of 20
Reader's step lines that parse as a Core statement (bullet and "(line N)" removed) 1 of 66 (2%)
The same step lines after 8 mechanical rewrites (verb forms and ":" only, listed below) 37 of 66 (56%)
Hand-written Core versions that compile 20 of 20

The English is written to describe code (third person, "Sets total to 0", "Gives back 0"), and Core is written as instructions ("Set total to 0", "Give 0"); the Core above is printed from the meaning tree instead. The remaining sentence shapes are listed below by how often each appears.

Gap list (reader line shapes that do not parse as Core)#

Reader shape Lines Example What Core writes How the reader converges
Ask: 16 Ask: Member and total is at least 100? When <condition>: … Otherwise: Print a question as When …: with the Yes branch indented under it and the No branch as Otherwise:; keep "Ask" only in the picture.
Gives back 15 Gives back 0 Give <value> Print "Give"; Core also accepts "Give back".
Answer: 9 Answer: Yes Give <value> In a rule card, an answer is what the function gives back: print Give "A", Give 15, Give yes.
Writes a log or message 6 Writes a log or message: "Hello, {name}!" — calls: print("Hello, {name say <value> A print/log call becomes say "…" with {name} holes (already the reader's text style).
code shown as code (… (code, not explained)) 5 return total * 0.2 (code, not explained) — means: return total * 0.2 the expression itself Expressions the reader shows as code (return total * 0.2) need the No-loss meaning model to print as Core expressions (Give total * 0.2).
Sets 3 Sets total to 0 Set <name> to <value> Imperative verb ("Set", not "Sets"). Same words otherwise.
For each 2 For each o in orders For each <item> in <list>: Add the closing ":" and drop the separate "For each:" line; a range(...) loop becomes For each i from 1 to n:.
Adds 2 Adds o price to total Increase <name> by <value> / Add <item> to <list> Print "Increase total by o price" for numbers and "Add … to …" for lists; possessives become o's price.
Counts i 2 Counts i from 1 to n — in: range(1, n + 1) (design needed) See the RFC section "Reading and writing converge".
Stores 1 Stores the word entry in counts under word in counts — value: counts.g Set <map> at <key> to <value> Print Set counts at word to (counts at word otherwise 0) + 1; needs the meaning model for .get(k, 0) (shown as code today).
Tries 1 Tries the next steps and handles the errors named below the protected statement, then If this fails: Core attaches If this fails: to the statement before it; the reader should print the protected steps, then If this fails: (a block of several steps needs a Core Try: block, planned).
Stop: 1 Stop: ValueError: "Insufficient funds" Stop with "<message>" Print Stop with "Insufficient funds"; the error kind stays in Details.
Repeats 1 Repeats while n is more than 0 Repeat while <condition>: Imperative verb ("Repeat", not "Repeats") and a closing ":".
Subtracts 1 Subtracts 1 from n Decrease <name> by <value> Print "Decrease n by 1".

The mechanical rewrites measured above:

  • Sets (.+?) to (.+) → Set $1 to $2
  • Gives back (.+) → Give $1
  • Answer: (.+) → Give $1
  • Repeats while (.+) → Repeat while $1:
  • For each (.+?) in (.+) → For each $1 in $2:
  • Subtracts (.+?) from (.+) → Decrease $2 by $1
  • Adds (.+?) to (.+) → Increase $2 by $1
  • Ask: (.+)\? → When $1:

Lines that still fail after them need the reader to print values as Core expressions (possessives such as o's price, code shown as code, and "Writes a log or message — calls: print(…)").

Other differences that are not single lines:

  • The title line. The reader prints Calculate discount and You give it: total, member; Core writes To calculate discount: and Receive total and member.
  • Yes/no function names. Python is_adult reads as "Is adult?". "is" is a Thunder word, so Core v0 cannot use it in a name (the Core versions say check adult). Next: a To decide whether <name>: form that makes a yes/no function, matching the reader's question title.
  • Truthiness. Python if member: reads as "Member?"; Core asks for member is true, because "truthy" differs between languages. The reader should print the explicit comparison when it knows the value is yes/no.
  • Possessives. The reader prints o price; Core writes o's price (the reader already uses 's in some places).
  • Line numbers. (line N) is a link to the original code; Core files have their own lines. Thunder Text keeps them as trailing comments (# line 4) once the reader prints Core.

The 20 functions#

1. calculate_discount#

Python:

Python
def calculate_discount(total, member):
    if member and total >= 100:
        return total * 0.2
    return 0

What the reader prints today (Thunder Text):

Output
Calculate discount
  You give it: total, member
  - Ask: Member and total is at least 100?  (line 2)
    Yes:
      - `return total * 0.2` (code, not explained) — means: return total * 0.2  (line 3)
    No: continue
  - Gives back 0  (line 4)

Thunder Core a person would write (compiles):

Output
To calculate discount:
  Receive total and member
  When member is true and total is at least 100:
    Give total * 0.2
  Give 0

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 3.

Printed as Core by thunder read --as-core (exact):

Output
To calculate discount:
  Receive total and member
  When member is true and total is at least 100:
    Give total * 0.2
  Give 0

Run next to the original: 4 of 4 inputs give the same result.

2. greet#

Python:

Python
def greet(name):
    print(f"Hello, {name}!")

What the reader prints today (Thunder Text):

Output
Greet
  You give it: name
  - Writes a log or message: "Hello, {name}!" — calls: print("Hello, {name}!")  (line 2)

Thunder Core a person would write (compiles):

Output
To greet:
  Receive name
  say "Hello, {name}!"

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 1.

Printed as Core by thunder read --as-core (exact):

Output
To greet:
  Receive name
  say "Hello, {name}!"

Run next to the original: 2 of 2 inputs give the same result.

3. total_paid#

Python:

Python
def total_paid(orders):
    total = 0
    for o in orders:
        if o.paid:
            total += o.price
    return total

What the reader prints today (Thunder Text):

Output
Total paid
  You give it: orders
  - Sets total to 0  (line 2)
  - For each o in orders  (line 3)
    For each:
      - Ask: Is o paid?  (line 4)
        Yes:
          - Adds o price to total  (line 5)
        No: continue
  - Gives back total  (line 6)

Thunder Core a person would write (compiles):

Output
To total paid:
  Receive orders
  Set total to 0
  For each order in orders:
    When order's paid is true:
      Increase total by order's price
  Give total

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 5.

Printed as Core by thunder read --as-core (exact):

Output
To total paid:
  Receive orders
  Set total to 0
  For each o in orders:
    When o's paid is true:
      Increase total by o's price
  Give total

Run next to the original: 2 of 2 inputs give the same result.

4. is_adult#

Python:

Python
def is_adult(age):
    return age >= 18

What the reader prints today (Thunder Text):

Output
Is adult: a rule
  You give it: age
  - Ask: Age is at least 18?  (line 2)
    Yes:
      - Answer: Yes  (line 2)
    No:
      - Answer: No  (line 2)

Thunder Core a person would write (compiles):

Output
To check adult:
  Receive age
  Give age is at least 18

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 3.

Printed as Core by thunder read --as-core (exact):

Output
To is_adult:
  Receive age
  Give age is at least 18

Run next to the original: 3 of 3 inputs give the same result.

5. biggest#

Python:

Python
def biggest(x, y, z):
    if x >= y and x >= z:
        return x
    elif y >= z:
        return y
    else:
        return z

What the reader prints today (Thunder Text):

Output
Biggest
  You give it: x, y, z
  - Ask: X is at least y and x is at least z?  (line 2)
    Yes:
      - Gives back x  (line 3)
    No:
      - Ask: Is y at least z?  (line 4)
        Yes:
          - Gives back y  (line 5)
        No:
          - Gives back z  (line 7)

Thunder Core a person would write (compiles):

Output
To biggest:
  Receive x, y and z
  When x is at least y and x is at least z:
    Give x
  Otherwise when y is at least z:
    Give y
  Otherwise:
    Give z

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 5.

Printed as Core by thunder read --as-core (exact):

Output
To biggest:
  Receive x, y and z
  When x is at least y and x is at least z:
    Give x
  Otherwise when y is at least z:
    Give y
  Otherwise:
    Give z

Run next to the original: 4 of 4 inputs give the same result.

6. fizzbuzz#

Python:

Python
def fizzbuzz(n):
    for i in range(1, n + 1):
        if i % 15 == 0:
            print("FizzBuzz")
        elif i % 3 == 0:
            print("Fizz")
        elif i % 5 == 0:
            print("Buzz")
        else:
            print(i)

What the reader prints today (Thunder Text):

Output
Fizzbuzz
  You give it: n
  - Counts i from 1 to n — in: range(1, n + 1)  (line 2)
    For each:
      - Ask: Is i % 15 0?  (line 3)
        Yes:
          - Writes a log or message: "FizzBuzz" — calls: print("FizzBuzz")  (line 4)
        No:
          - Ask: Is i % 3 0?  (line 5)
            Yes:
              - Writes a log or message: "Fizz" — calls: print("Fizz")  (line 6)
            No:
              - Ask: Is i % 5 0?  (line 7)
                Yes:
                  - Writes a log or message: "Buzz" — calls: print("Buzz")  (line 8)
                No:
                  - Writes a log or message: i — calls: print(i)  (line 10)

Thunder Core a person would write (compiles):

Output
To fizzbuzz:
  Receive n
  For each i from 1 to n:
    When i mod 15 is 0:
      say "FizzBuzz"
    Otherwise when i mod 3 is 0:
      say "Fizz"
    Otherwise when i mod 5 is 0:
      say "Buzz"
    Otherwise:
      say i

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 8.

Printed as Core by thunder read --as-core (exact):

Output
To fizzbuzz:
  Receive n
  For each i from 1 to n:
    When (i mod 15) is 0:
      say "FizzBuzz"
    Otherwise when (i mod 3) is 0:
      say "Fizz"
    Otherwise when (i mod 5) is 0:
      say "Buzz"
    Otherwise:
      say i

Run next to the original: 2 of 2 inputs give the same result.

7. average#

Python:

Python
def average(numbers):
    return sum(numbers) / len(numbers)

What the reader prints today (Thunder Text):

Output
Average
  You give it: numbers
  - `return sum(numbers) / len(numbers)` (code, not explained) — means: return sum(numbers) / len(numbers)  (line 2)

Thunder Core a person would write (compiles):

Output
To average:
  Receive numbers
  Give the sum of numbers / the count of numbers

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 1.

Printed as Core by thunder read --as-core (exact):

Output
To average:
  Receive numbers
  Give (the sum of numbers) / (the count of numbers)

Run next to the original: 3 of 3 inputs give the same result.

8. count_words#

Python:

Python
def count_words(text):
    counts = {}
    for word in text.lower().split():
        counts[word] = counts.get(word, 0) + 1
    return counts

What the reader prints today (Thunder Text):

Output
Count words
  You give it: text
  - Sets counts to an empty lookup table  (line 2)
  - For each word in the result of split — means: for each word in text.lower().split()  (line 3)
    For each:
      - Stores the word entry in counts under word in counts — value: counts.get(word, 0) + 1  (line 4)
  - Gives back counts  (line 5)

Thunder Core a person would write (compiles):

Output
To count words:
  Receive text
  Set counts to an empty map
  For each word in the words of lowercase of text:
    Set counts at word to (counts at word otherwise 0) + 1
  Give counts

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 4.

Printed as Core by thunder read --as-core (exact):

Output
To count words:
  Receive text
  Set counts to an empty map
  For each word in the parts of (the lowercase of text):
    Set counts at word to (counts at word otherwise 0) + 1
  Give counts

Run next to the original: 1 of 1 inputs give the same result.

9. apply_tax#

Python:

Python
TAX = 0.07

def apply_tax(price):
    return price * (1 + TAX)

What the reader prints today (Thunder Text):

Output
Apply tax
  You give it: price
  - `return price * (1 + TAX)` (code, not explained) — means: return price * (1 + TAX)  (line 4)

Thunder Core a person would write (compiles):

Output
Keep tax at 7%

To apply tax:
  Receive price
  Give price * (1 + tax)

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 1.

Printed as Core by thunder read --as-core (exact):

Output
Keep TAX at 0.07

To apply tax:
  Receive price
  Give price * (1 + TAX)

Run next to the original: 2 of 2 inputs give the same result.

10. shipping_cost#

Python:

Python
def shipping_cost(weight):
    if weight > 10:
        return 15
    elif weight > 5:
        return 10
    else:
        return 5

What the reader prints today (Thunder Text):

Output
Shipping cost: a rule
  You give it: weight
  - Ask: Weight is more than 10?  (line 2)
    Yes:
      - Answer: 15  (line 2)
    No:
      - Ask: Weight is more than 5?  (line 4)
        Yes:
          - Answer: 10  (line 4)
        No:
          - Answer: 5  (line 6)

Thunder Core a person would write (compiles):

Output
To shipping cost:
  Receive weight
  When weight is more than 10:
    Give 15
  Otherwise when weight is more than 5:
    Give 10
  Otherwise:
    Give 5

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 5.

Printed as Core by thunder read --as-core (exact):

Output
To shipping cost:
  Receive weight
  When weight is more than 10:
    Give 15
  Otherwise when weight is more than 5:
    Give 10
  Otherwise:
    Give 5

Run next to the original: 5 of 5 inputs give the same result.

11. safe_divide#

Python:

Python
def safe_divide(x, y):
    try:
        return x / y
    except ZeroDivisionError:
        return None

What the reader prints today (Thunder Text):

Output
Safe divide
  You give it: x, y
  - Tries the next steps and handles the errors named below  (line 2)
    - `return x / y` (code, not explained) — means: return x / y  (line 3)
    If ZeroDivisionError goes wrong:
      - Gives back None  (line 5)

Thunder Core a person would write (compiles):

Output
To safe divide:
  Receive x and y
  Give x / y
  If this fails:
    Give nothing

Reader's text compiles as Core: no. Step lines that parse as Core: 1 of 4.

Printed as Core by thunder read --as-core (compiles; some lines not translated):

Output
To safe divide:
  Receive x and y
  # Not translated (line 2): Core has no step for a Python try (an error handler that names its error kinds) yet
  Stop with "Line 2 of the Python was not translated: try:"

12. withdraw#

Python:

Python
def withdraw(balance, amount):
    if amount > balance:
        raise ValueError("Insufficient funds")
    return balance - amount

What the reader prints today (Thunder Text):

Output
Withdraw
  You give it: balance, amount
  - Ask: Is amount more than balance?  (line 2)
    Yes:
      - Stop: ValueError: "Insufficient funds"  (line 3)
    No: continue
  - `return balance - amount` (code, not explained) — means: return balance - amount  (line 4)

Thunder Core a person would write (compiles):

Output
To withdraw:
  Receive balance and amount
  When amount is more than balance:
    Stop with "Insufficient funds"
  Give balance - amount

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 3.

Printed as Core by thunder read --as-core (exact):

Output
To withdraw:
  Receive balance and amount
  When amount is more than balance:
    Stop with "Insufficient funds"
  Give balance - amount

Run next to the original: 3 of 3 inputs give the same result.

13. countdown#

Python:

Python
def countdown(n):
    while n > 0:
        print(n)
        n -= 1

What the reader prints today (Thunder Text):

Output
Countdown
  You give it: n
  - Repeats while n is more than 0  (line 2)
    For each:
      - Writes a log or message: n — calls: print(n)  (line 3)
      - Subtracts 1 from n  (line 4)

Thunder Core a person would write (compiles):

Output
To countdown:
  Receive n
  Repeat while n is more than 0:
    say n
    Decrease n by 1

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 3.

Printed as Core by thunder read --as-core (exact):

Output
To countdown:
  Receive n
  Repeat while n is more than 0:
    say n
    Set n to n - 1

Run next to the original: 2 of 2 inputs give the same result.

14. sum_up#

Python:

Python
def sum_up(n):
    total = 0
    for i in range(1, n + 1):
        total += i
    return total

What the reader prints today (Thunder Text):

Output
Sum up
  You give it: n
  - Sets total to 0  (line 2)
  - Counts i from 1 to n — in: range(1, n + 1)  (line 3)
    For each:
      - Adds i to total  (line 4)
  - Gives back total  (line 5)

Thunder Core a person would write (compiles):

Output
To sum up:
  Receive n
  Set total to 0
  For each i from 1 to n:
    Increase total by i
  Give total

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 4.

Printed as Core by thunder read --as-core (exact):

Output
To sum up:
  Receive n
  Set total to 0
  For each i from 1 to n:
    Increase total by i
  Give total

Run next to the original: 3 of 3 inputs give the same result.

15. paid_orders#

Python:

Python
def paid_orders(orders):
    return [o for o in orders if o.paid]

What the reader prints today (Thunder Text):

Output
Paid orders
  You give it: orders
  - Gives back the items in orders where paid — value: [o for each o in orders where o.paid]  (line 2)

Thunder Core a person would write (compiles):

Output
To paid orders:
  Receive orders
  Give orders where paid is true

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 1.

Printed as Core by thunder read --as-core (exact):

Output
To paid orders:
  Receive orders
  Give orders where paid is true

Run next to the original: 2 of 2 inputs give the same result.

16. cheapest_first#

Python:

Python
def cheapest_first(items):
    return sorted(items, key=lambda i: i.price)

What the reader prints today (Thunder Text):

Output
Cheapest first
  You give it: items
  - Gives back the result of sorted — value: sorted(items, key: (i) => i.price)  (line 2)

Thunder Core a person would write (compiles):

Output
To cheapest first:
  Receive items
  Give items sorted by price

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 1.

Printed as Core by thunder read --as-core (exact):

Output
To cheapest first:
  Receive items
  Give items sorted by price

Run next to the original: 2 of 2 inputs give the same result.

17. grade#

Python:

Python
def grade(score):
    if score >= 90:
        return "A"
    if score >= 80:
        return "B"
    if score >= 70:
        return "C"
    return "F"

What the reader prints today (Thunder Text):

Output
Grade: a rule
  You give it: score
  - Ask: Score is at least 90?  (line 2)
    Yes:
      - Answer: A  (line 2)
    No:
      - Ask: Score is at least 80?  (line 4)
        Yes:
          - Answer: B  (line 4)
        No:
          - Ask: Score is at least 70?  (line 6)
            Yes:
              - Answer: C  (line 6)
            No:
              - Answer: F  (line 8)

Thunder Core a person would write (compiles):

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

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 7.

Printed as Core by thunder read --as-core (exact):

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

Run next to the original: 5 of 5 inputs give the same result.

18. full_name#

Python:

Python
def full_name(first, last):
    return f"{first} {last}"

What the reader prints today (Thunder Text):

Output
Full name
  You give it: first, last
  - Gives back "«first» «last»"  (line 2)

Thunder Core a person would write (compiles):

Output
To full name:
  Receive first and last
  Give "{first} {last}"

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 1.

Printed as Core by thunder read --as-core (exact):

Output
To full name:
  Receive first and last
  Give "{first} {last}"

Run next to the original: 1 of 1 inputs give the same result.

19. is_empty_cart#

Python:

Python
def is_empty_cart(cart):
    return len(cart) == 0

What the reader prints today (Thunder Text):

Output
Is empty cart
  You give it: cart
  - Gives back whether the length of cart is 0 — value: len(cart) == 0  (line 2)

Thunder Core a person would write (compiles):

Output
To check empty cart:
  Receive cart
  Give cart is empty

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 1.

Printed as Core by thunder read --as-core (exact):

Output
To is_empty_cart:
  Receive cart
  Give (the count of cart) is 0

Run next to the original: 3 of 3 inputs give the same result.

20. clamp#

Python:

Python
def clamp(value, low, high):
    if value < low:
        return low
    if value > high:
        return high
    return value

What the reader prints today (Thunder Text):

Output
Clamp
  You give it: value, low, high
  - Ask: Is value less than low?  (line 2)
    Yes:
      - Gives back low  (line 3)
    No: continue
  - Ask: Is value more than high?  (line 4)
    Yes:
      - Gives back high  (line 5)
    No: continue
  - Gives back value  (line 6)

Thunder Core a person would write (compiles):

Output
To clamp:
  Receive value, low and high
  When value is less than low:
    Give low
  When value is more than high:
    Give high
  Give value

Reader's text compiles as Core: no. Step lines that parse as Core: 0 of 5.

Printed as Core by thunder read --as-core (exact):

Output
To clamp:
  Receive value, low and high
  When value is less than low:
    Give low
  When value is more than high:
    Give high
  Give value

Run next to the original: 4 of 4 inputs give the same result.