Pylons
A pretty basic stack-based language, written to understand how stack-based languages work.
morganthrapp · Turing complete: unknown · ●○○ easy
Tested with 8 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
Pylons is a small golfing language written in Python 3 by morganthrapp. Each character is one command. A digit pushes itself, a quoted string pushes the codes of its characters, and the capital letters A to E are variables that start as -1, 10, 100, 1000 and 0.
Read the story
Its arithmetic reads the stack from the top down. A command takes the top item and the one below it and works out top OP below, so 12- is 2 minus 1, not 1 minus 2. When the program ends the whole stack is printed as a Python list.
The machine
| Command | Does |
|---|---|
0-9, "text" | Push a digit, or the codes of the characters |
+ - * / % e | Top OP below; / is floor division and e is power |
& \| ^ < > | Bitwise, top OP below |
! ~ q d t b | Factorial, not, square root, duplicate, keep the top, keep the bottom |
, \ ` v l s x k | Drop, swap, sort, reverse, length, sum, clear, range | |
g m _ | Greater than, is prime, is in the rest; each leaves a single value |
p | Print the stack as a list |
c j | Print the stack as characters or joined up, then stop |
i | Push the arguments |
The full language also has loops, variables, functions, lists and conditional jumps written as small bracketed forms such as {command,count}. This implementation has the commands above and stops with a reason on the rest.
Example
The second one prints its stack with p and then once more at the end.
The second one prints its stack with p and then once more at the end. The third makes the range from 2 to 5. The last reverses the codes before printing them as characters.
Patterns it teaches
- Stack machines: one stack, read from the top down.
- Code golf: one character per command, and a string is just a run of numbers.
Try this
- Print the sum of the numbers 1 to 9.
- Print 1000 squared with as few characters as you can.
- Hard: print
Hello, World!backwards.
Further
- The reference interpreter, in Python 3
See also
Also in Golfing
Write your own in Run Convert a program from Pylons
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: pylons.
Command line
shib run pylons -e '2q'shib manual pylonsSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/pylons.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language