Pyth
Python written in prefix notation, one character per function, with no brackets to close.
isaacg, 2014 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 12 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
isaacg made Pyth in 2014 as a golfing language for people who think in Python rather than in stacks. A Pyth program is compiled almost one to one into a Python program and then run. Every function is one character and has a fixed number of arguments, so +1*2 3 can only mean 1 + 2 * 3 and no brackets are needed. When the code runs out, the input Q fills whatever is still missing, so *FSQ is a whole factorial program.
Read the story
Each expression at the top level is printed. A string runs to the end of the program if it is never closed, which makes "Hello, World! a complete program.
The machine
Values are Python's own, big integers, floats, strings and lists, printed the way Python prints them.
| Code | Does |
|---|---|
+ - * / % ^ | Arithmetic; also join, remove, repeat, count, every nth, powers of a list |
h t e | Head, tail, end; on a number add one, take one, last digit |
l s S U | Length, sum, sorted, range |
j c r | Join, chop, range; r with a code changes case or counts runs |
m f o u | Map with d, filter with T, order by N, reduce with G and H |
F V I W # | For, for each in N, if, while, loop until an error |
= ~ J K | Assign; =+Z1 adds one to Z |
Q z w E | Input as a value, a line, a line, a value |
Variables start set, Z 0, T 10, d a space, k empty, b a newline, N a quote, Y an empty list and G the alphabet.
Pyth also has a packed string, .". The first two characters give the lowest and the highest character of the text, and the rest is one big base 256 number that is written out in that range. The Hello World on Try It Online is packed this way into 15 bytes.
Example
S5 is the list 1 to 5 and *F folds multiplication over it.
S5 is the list 1 to 5 and *F folds multiplication over it.
m*ddUT squares each number below ten and jd joins them with spaces.
FizzBuzz to 15. !%N3 is True on multiples of three, and True times a string is the string.
This implementation follows the reference compiler, isaacg1/pyth on GitHub, for the core of the language, 55 functions, the four lambdas, the loops and the packed strings. Anything else, such as the rarer . commands, dictionaries or most of the sugar suffixes, stops the run with its name rather than guess.
Patterns it teaches
- Code golf: fixed arities instead of brackets, and the input filling the gaps.
Try this
- Print the sum of the numbers 1 to 100.
- Read a line and print it with its words in reverse order.
- Hard: print the first ten Fibonacci numbers with
u.
Further
- esolangs.org/wiki/Pyth
- The reference compiler, in Python, with its documentation
- Related: CJam, GolfScript
See also
Golfing languages
Stack-based
Write your own in Run Convert a program from Pyth
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: pyth.
Command line
shib run pyth -e '_z' --input 'hello
'shib manual pythSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/pyth.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org