esolang

Purl

A program is a knitting pattern. Knits are ones, purls are zeros, and each row ends on a stack.

GotCubes, 2021 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hello, world!

The idea

GotCubes made Purl in 2021. Its programs are called patterns, and each of its 15 instructions is a knitting term. K3 is three knit stitches and P2 two purls, and a row of them spells a binary number, knits for 1 and purls for 0. K1 P2 K1 P3 is 1001000, which is 72, the letter H. The specification admits that the patterns may make rather awkward knitted works.

Read the story

Each line is a row with a value of its own that starts at 0. EOR, the end of the row, pushes that value onto the one stack, and DROP, a dropped stitch, pops a value and prints it as a character. There is no branch, only REP, which repeats the deeper rows below it while the top of the stack is not 0.

The machine

StitchKnittingDoes
Kn PnKnit, purln ones or n zeros of the row's value
BEG EORBeginning, end of rowPop into the row; push the row
CONTContinuePop
CO MBCast on, make bobbleRead a number or a character into the row
DROP SLDrop stitch, slip stitchPop and print a character or a number
TYWTurn your workTurn the stack over
INC DEC JOIN YOIncrease, decrease, join, yarn overAdd, take, multiply or divide the row by the top
REPRepeatRun the deeper rows below while the top is not 0
BOBind offEnd the program

INC and the other three leave the top where it is, so INC EOR on a fresh row copies the top.

Example

The Hello World knits the 13 characters onto the stack backwards and drops them off again.

The Hello World knits the 13 characters onto the stack backwards and drops them off again.

The truth machine pushes its input. On 0 it skips the repeat and prints 0 once; on 1 it copies and prints the 1 forever.

Expected: 0

Two rows read two numbers, and the third pops one into its own value and multiplies it by the other.

Expected: 42

The specification also has a calculator for + - * /. With no way to branch on a value, it subtracts each operator's code in turn and nests a REP for every one that does not match.

Patterns it teaches

  • Camouflage: a program that reads as a knitting pattern.
  • Stack machines: one stack, with a row value as its only register.

Further

Stack-based

Write your own in Run Convert a program from Purl

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: purl.

Command line

shib run purl -e 'CO EOR
REP
    INC EOR
    SL
SL' --input '0'
shib manual purl

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/purl.js

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

Source esolangs.org (CC0) · Edit on esolangs.org