esolang

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

Expected: Hello, World!

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

CommandDoes
0-9, "text"Push a digit, or the codes of the characters
+ - * / % eTop OP below; / is floor division and e is power
& \| ^ < >Bitwise, top OP below
! ~ q d t bFactorial, 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
pPrint the stack as a list
c jPrint the stack as characters or joined up, then stop
iPush 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.
Expected: [3] [3]
Expected: [2, 3, 4, 5]
Expected: cba

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

  1. Print the sum of the numbers 1 to 9.
  2. Print 1000 squared with as few characters as you can.
  3. Hard: print Hello, World! backwards.

Further

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 pylons

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/pylons.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language