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
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
| Stitch | Knitting | Does |
|---|---|---|
Kn Pn | Knit, purl | n ones or n zeros of the row's value |
BEG EOR | Beginning, end of row | Pop into the row; push the row |
CONT | Continue | Pop |
CO MB | Cast on, make bobble | Read a number or a character into the row |
DROP SL | Drop stitch, slip stitch | Pop and print a character or a number |
TYW | Turn your work | Turn the stack over |
INC DEC JOIN YO | Increase, decrease, join, yarn over | Add, take, multiply or divide the row by the top |
REP | Repeat | Run the deeper rows below while the top is not 0 |
BO | Bind off | End 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.
Two rows read two numbers, and the third pops one into its own value and multiplies it by the other.
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
See also
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 purlSource
- 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