Haystack
The program is a haystack and | is the needle. The pointer wanders the grid until it finds it.
Kade Robertson, 2015 · Turing complete: unknown · ●●○ moderate
Tested with 9 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Kade Robertson started Haystack in 2015 and rebuilt it in November 2016 as haystack_new.py, the version described below. It is a grid language in the line of Befunge. The pointer starts at the top left moving right, wraps around every edge, and the program ends the moment it lands on a |. A program without a reachable needle never ends.
Read the story
The stack holds Python 3 values, so it is richer than a Fungeoid's stack of numbers. There are strings, floats, booleans and lists, and the operators mean what they mean in Python. + adds numbers and joins strings, * repeats a string, D divides into a float, and o prints whatever is on top the way print would.
The machine
| Char | Does |
|---|---|
> < ^ v | Point the pointer |
/ \ | Mirrors |
? | Pop; keep going if it is truthy, otherwise turn right |
0-9 | A run of digits is one number |
"..." | Push the text up to the next quote |
+ - * D % | Arithmetic; D is true division |
l L = | Less, greater, equal, giving True or False |
d , ; @ | Duplicate, drop, swap, move the top to the bottom |
o O c C | Print the top, or its character, without popping; the capitals add a newline |
i I | Read a line as a Python literal, or as text |
a A | Push the alphabet in lowercase or uppercase |
r R f F | The lists 0 to n-1 and 1 to n+1, factorial, Fibonacci |
b B n N ~ | To and from binary, round, int, square root |
m M e E z Z u U | Min, max, enumerate, sort pairs, zip, split off the first or last item |
\| | The needle, which ends the program |
Example
A loop needs the second dimension.
A loop needs the second dimension. This one prints 5 down to 1. The pointer goes down from v, right along the middle row, and ? sends it up and round again while the count is not 0. At 0 it turns down into the needle.
5v <
>O1-d?^
|
Patterns it teaches
- Two-dimensional control flow: loops are drawn as circuits, and the only way out is to steer onto the needle.
- Stack machines: one stack, but of Python values rather than numbers.
Further
- The reference interpreter, in Python
See also
Also in Spatial (2D and up)
Write your own in Run Convert a program from Haystack
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: haystack.
Command line
shib run haystack -e 'Io|' --input 'needle
'shib manual haystackSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/haystack.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language