1+
The only number you can write is 1. Everything else is built from ones, one plus at a time.
Jeremy Tan (Parcly Taxel), 2014 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Jeremy Tan (Parcly Taxel) thought of 1+ in 2012 and finished the spec and interpreter in 2014. It is a stack language inspired by FALSE, Piet and Wang's B-machine. The rule that gives it its name: 1 is the only literal. To push 72 you write something like 11+"""1+"****. How few ones a number needs is a real maths question, called integer complexity.
Read the story
There is only one conditional, <, and only one control structure, #. # pops n and jumps to just after the nth # in the program. Loops are jumps back, the end is a jump forward. Subroutines, (name|code), have their own # numbering, and they can call themselves.
The machine
One stack of non-negative integers. Popping an empty stack is an error.
| Char | Does |
|---|---|
1 | Push 1 |
+ * | Pop two, push the sum or product |
" ^ | Duplicate; swap |
/ \ | Top to bottom; bottom to top |
< | Pop a and b; push 0 if a < b, else 1 |
. , | Read a number or a character (0 at end of input) |
: ; | Pop and print as a number or a character |
# | Pop n, continue after the nth # (counting from 0) |
(name\|code) (name) | Define a subroutine and run it; run it again |
[ … ] | Comment |
Example
The truth-machine.
The truth-machine. . reads the number and 1# jumps past the second #. Then it prints the number and computes number + 1 compared with 1: for 0 that gives 1, plus one is 2, so # jumps past the last # and the program ends. For 1 it gives 0, plus one is 1, and # jumps back to print 1 again, forever.
Patterns it teaches
- Stack machines: a small stack machine with rotation instead of variables.
- Turing tarpit: one literal, one test, one jump, and still enough.
- Quine: the specification has two quines, both built mostly from long runs of
1+. - Turing completeness: Boolfuck is translated into 1+.
Try this
- Print the number 10.
- Print
Hi(72 and 105). - Hard: read a number n and print n, n−1, …, 1. Remember that numbers cannot go below 0.
Further
See also
Stack-based
Write your own in Run Convert a program from 1+
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: one-plus.
Command line
shib run one-plus -e '1##,";1+1<1+#' --input 'hi'shib manual one-plusSource
- Module
langs/stack/ports.js- Interpreter
langs/stack/one-plus.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org