Needle

From Esolang
Jump to navigation Jump to search

Needle is an esolang by User:ChuckEsoteric08 in 2025.

Description

The language uses wrapping tape of 3 cells and program inside an infinite loop

  • _ - decrements current cell and moves right. Decrementing zero does nothing.
  • (...) - increment current cell and if result is 1 then run code inside the brackets. Can be nested.

There are optional IO commands:

  • ; - input into a current cell. Can be either number or ASCII character depending on the implementation
  • * - output cell as either number or ASCII character depending on implementation

Computational class

Needle is Turing-complete since Minsky machine could be compiled into it. For the simplicity I would use a subset called Infinite Minsky machine (IMM).

Notation

Here I would use a specific notation where [x;y] would execute code x y times. I would also definine following commands:

NEXT = ()_
DEC = _ NEXT NEXT

Infinite Minsky machine

Language has 2 registers: A and B. Program like in Needle would be inside an infinite loop.

INC x y

Increment x and move y commands forward.

DEC x y

Decrement x (if 0 do nothing) and move y commands forward.

IF x y

If x is 0 move y commands forward, else execute next one.

From IMM to Needle

INC A y becomes:

DEC ( NEXT () NEXT NEXT [();y] ) DEC 

Becoming:

_()_()_(()_()()_()_[();y])_()_()_ 

INC B y becomes:

DEC ( NEXT NEXT () NEXT [();y] ) DEC 

Becoming:

_()_()_(()_()_()()_[();y])_()_()_ 

DEC A y becomes:

DEC ( NEXT _ NEXT [();y] ) DEC 

Becoming:

_()_()_(()__()_[();y])_()_()_ 

DEC B y becomes:

DEC ( NEXT NEXT _ [();y] ) DEC 

Becoming:

_()_()_(()_()__[();y])_()_()_ 

IF A y becomes:

DEC ( () NEXT ( NEXT NEXT [();y-1] NEXT ) _ NEXT ) DEC

Becoming:

_()_()_(()()_(()_()_[();y-1]()_)_()_)_()_()_ 

IF B y becomes:

DEC ( () NEXT NEXT ( NEXT [();y-1] NEXT NEXT ) _ ) DEC 

Becoming:

_()_()_(()()_()_(()_[();y-1]()_()_ )_)_()_()_

Example

Set Register A to 4 and then decrease it to zero, after which increment register B in an infinite loop:

INC A 1
INC A 1
INC A 1
INC A 1
IF A 2
DEC A 6
INC B 7 

Becomes:

_()_()_(()_()()_()_())_()_()_
_()_()_(()_()()_()_())_()_()_
_()_()_(()_()()_()_())_()_()_
_()_()_(()_()()_()_())_()_()_
_()_()_(()()_(()_()_()()_)_()_)_()_()_
_()_()_(()__()_()()()()()())_()_()_
_()_()_(()_()_()()_()()()()()()())_()_()_