Wise
A stack of integers and nothing but bitwise operations. Even adding one takes two commands.
Wheat Wizard, 2017 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
Wheat Wizard made Wise in 2017. It has twelve commands and none of them is arithmetic in the usual sense. There is and, or, xor, not, a shift each way and a negation. Adding one is ~-: not gives −x−1, and negating that gives x+1. A number is built bit by bit from 1 with < and ~-.
Read the story
The esolangs.org page called Wise describes a different language from 2023. This implementation follows the 2017 interpreter that Try It Online runs.
The machine
| Command | Does |
|---|---|
& \| ^ | Pop two, push and, or, xor |
~ | Not, −x−1 |
- | Negate |
< > | Shift left, shift right |
: | Duplicate |
? ! | Move the top to the bottom, the bottom to the top |
[ ] | Loop while the top is not 0; nothing is popped |
Numbers are unbounded. An empty stack gives 0 when popped. At the end the stack is printed from the bottom up, each number as a character mod 256, followed by a newline. That is the -a flag, which Try It Online's Hello World uses; this implementation always prints that way.
Example
The second program makes 1, shifts it six times to 64, adds one for A, then copies and adds one twice.
The second program makes 1, shifts it six times to 64, adds one for A, then copies and adds one twice.
Patterns it teaches
- Turing tarpit: a handful of bit operations, and every number has to be built from them.
- Stack machines:
?and!turn the stack into a ring.
Try this
- Print
0, which is 48. - Print
ABCDEFGHwith a loop. - Hard: add two numbers using only and, xor and shifts.
Further
- The reference interpreter, in Python
See also
Stack-based
Write your own in Run Convert a program from Wise
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: wise.
Command line
shib run wise -e '~-<<<<<<[:>]'shib manual wiseSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/wise.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org