Pyt
A stack language where each digit is its own number and an empty stack reads the input.
mudkip201 · Turing complete: unknown · ●●○ moderate
Tested with 8 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
Pyt is a golfing language by mudkip201, written in Python 2. Every command is one character, many of them outside ASCII. ² squares, ř makes the range 1 to n, Ƈ turns a number into a character. A digit pushes only itself, so 72 has to be built, for example as 89*.
Read the story
There is no command to read input in the usual sense. When a command pops from an empty stack, Pyt reads the next line of input instead, as a number, a list or text. At the end every item on the stack is printed on its own line.
The machine
| Command | Does |
|---|---|
0 to 9 | Push one digit |
+ - * / % | Arithmetic with the top on the right; on two lists it works item by item |
⁺ ⁻ ² ³ | Add one, take one, square, cube; on a list it maps |
Đ ŕ ⇹ | Duplicate, drop, swap |
á Á | Wrap the whole stack in a list, unwrap a list onto the stack |
ř Σ Π Ł | Range 1 to n, sum, product, length |
Ƈ ǰ | Number to character, join a list into a string |
? … : … ; | If the top is 0, skip to :; at : skip to ; |
` … ł | Jump back to the backtick while the top is not 0 |
Example
The Hello World from Try It Online builds each character code from single digits, wraps the stack in a…
The Hello World from Try It Online builds each character code from single digits, wraps the stack in a list with á, turns the codes into characters with Ƈ and joins them with ǰ.
ř pops from an empty stack, so it reads 6 and makes the list 1 to 6, and Π multiplies it.
A countdown. Đ⁻ copies the top and takes one off, and ł jumps back to the backtick until the top is 0.
A list prints the way Python 2 prints it.
This implementation follows the reference interpreter, mudkip201/pyt on GitHub, as Try It Online runs it. It has 46 of the commands besides the digits and constants. The rest, such as roots, trigonometry and number theory, stop the run with their name.
Patterns it teaches
- Code golf: a large alphabet of one-character commands.
- Stack machines: input arrives whenever the stack runs dry.
Try this
- Print the sum of the squares of 1 to 10.
- Read two numbers and print the larger one.
- Hard: print "Hi" with digits,
á,Ƈandǰ.
Further
- The reference interpreter, in Python 2
- Related: Pushy, CJam
See also
Also in Golfing
Write your own in Run Convert a program from Pyt
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: pyt.
Command line
shib run pyt -e '+' --input '3
4
'shib manual pytSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/pyt.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language