Programs that read like English.

Moth is a small programming language with no symbols to learn. You write say, if and repeat, draw pictures, make games, and when something goes wrong, it tells you in plain words.

$ moth build hello.moth  get moth

  • runs in your browser
  • engines that agree
  • runs without JavaScript too
  • a compiler written in Moth
  • no dependencies
welcome.moth

        

      

What it can do

Everything below runs in the playground underneath, with nothing to install.

Words, not symbols

if age is at least 18, not if (age >= 18) {. Lists, records and dictionaries are written the way you'd say them.

Mistakes in plain words

It points at the exact spot, and guesses what you meant.

line 2: 'totl' has no value yet.
Did you mean 'total'?

Games and apps

Keys, clicks and timers. Snake is 110 lines, and runs right here.

Engines that agree

A bytecode VM, a JIT to JavaScript, WebAssembly that Moth writes byte by byte, and machine code, written by a compiler in Moth. Thousands of random programs check they say the same.

A compiler written in Moth

2,400 lines of Moth that compile any Moth program, itself included, to exactly what the JIT writes, byte for byte. And moth.exe, Moth in machine code, builds itself with no JavaScript at all.

Debug backwards

Step through a run in either direction: the line about to run, every variable, and the picture as it was.

Numbers that add up

0.1 + 0.2 is 0.3, as in a spreadsheet. Numbers can have units: 5 km + 300 m is 5.3 km, and adding a time to a distance is a mistake that says so.

Tables and charts

read table "sales.csv", then for each row in sales where ..., total of price in sales and draw chart of price in sales.

Asks first

On your computer, a program asks before it reads or writes your files or goes online, as Deno does. --allow-read and the rest let it without asking.

Made with Moth

Click one to open it in the playground.

The playground ↓
↑ Home GitHub ↗
Code
Output