esolang

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

Expected: Hello, World!

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

CharDoes
> < ^ vPoint the pointer
/ \Mirrors
?Pop; keep going if it is truthy, otherwise turn right
0-9A 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 CPrint the top, or its character, without popping; the capitals add a newline
i IRead a line as a Python literal, or as text
a APush the alphabet in lowercase or uppercase
r R f FThe 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 UMin, 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.
Expected: 0.3333333333333333
Expected: needle

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?^
      |
Expected: 5 4 3 2 1

Patterns it teaches

Further

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 haystack

Source

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

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