FALSE
A Forth squeezed into single characters, with a 1024-byte compiler. One of the languages that started the esolang wave of 1993.
Wouter van Oortmerssen, 1993 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 3 examples and 3 known programs · Hello World on Try It Online: identical · Test method
Run it
Hello World
Expected output
Hello, World!
Output
The idea
Wouter van Oortmerssen wanted two things: a language that looked cryptic, and a compiler as small as possible. His compiler, in 68000 assembler for the Amiga, was 1024 bytes. The language it compiled was a stack language in the style of Forth, with every word shrunk to one symbol.
Read the story
FALSE is a real, usable language. It has numbers, arithmetic, 26 variables, strings and, most interestingly, lambdas: pieces of code you can push on the stack and run later. That is how it does if, while and functions.
FALSE matters mostly for what it started. It is credited with inspiring Brainfuck (also an Amiga, also a tiny-compiler challenge) and Befunge.
The machine
A stack of integers and lambdas, and 26 variables a–z.
| Char | Does |
|---|---|
123 'c | Push a number, or a character's code |
$ % \ @ ø | Dup, drop, swap, rot, pick (copy the nth item) |
+ - * / _ | Arithmetic; _ negates |
= > | Compare. True is −1 (all bits set), false is 0 |
& \| ~ | Bitwise and, or, not (they work as logic, thanks to −1) |
[ … ] | Push a lambda |
! | Run the lambda on top |
? | cond [ … ] ? runs the lambda if cond is true |
# | [cond] [body] # is a while loop |
a…z : ; | Push a variable reference; store into it; fetch from it |
. , "…" ^ | Print a number, print a character, print a string, read a character |
{ … } | Comment |
Example
Factorial, recursive, stored in variable f:
Factorial, recursive, stored in variable f:
[$1>[$1-f;!*]?]f: { if n > 1: n * f(n-1) }
5f;!. { prints 120 }
Walk through the definition: $1> asks "is n greater than 1?". If so, $1- pushes n−1, f;! fetches f and runs it (the recursion), and * multiplies. If not, n is left alone, so f(1) = 1.
A loop that prints the squares from 1 to 6:
1[$6>~][$$*." "1+]#% { 1 4 9 16 25 36 }
And cat: read until ^ returns −1.
The interpreter covers everything except the backtick (inline 68000 machine code). ø can also be typed as O.
Checked examples
Example
Expected output
120
Output
Example
Expected output
55
Output
Quirks
- FALSE (subset) implements part of the language, as described above.
- A run stops after 3,000,000 steps.
Try this
- Print the numbers 10 down to 1, separated by spaces.
- Store a lambda that doubles a number in
d, and use it three times on 5. - Hard: write FizzBuzz for 1 to 15. You will need
?twice and a trick for "else".
Patterns it teaches
- Stack machines: Forth's model with the words shrunk to symbols.
- Concatenative: programs are sequences you can cut and paste.
- Code as data: lambdas live on the stack and in variables, like numbers.
- Turing tarpit: not a tarpit itself, but its tiny-compiler challenge is where the tarpit tradition began.
Further
- esolangs.org/wiki/FALSE, with the original factorial example.
- Forth, the model; Brainfuck, the most famous child.
See also
Stack-based
Write your own in Run Convert a program from FALSE
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: false.
Command line
shib run false -e '"Hello, World!"'shib manual falseSource
- Module
langs/classic.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org