esolang

@!+-()

One accumulator and one queue. Named after six of its eight commands.

ChuckEsoteric08 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: HI

The idea

ChuckEsoteric08 made @!+-() with an accumulator and a queue as its only memory. The accumulator can count up and down and test for 0, and the queue is where everything else waits. To keep a number while working on another, a program puts it at the back of the queue and later takes it off the front.

Read the story

The specification shows it is Turing complete by translating Queuefuck into it, one command into a few.

The machine

CommandDoes
@Put the accumulator at the back of the queue
!Take the front of the queue into the accumulator
+ -Add 1 to the accumulator or take 1 from it
(Skip past the matching ) when the accumulator is 0
)Go back to the matching ( while the accumulator is above 0
, .Print the accumulator as a character; read a byte into it

As in the specification's JavaScript, + and - work modulo 256 with the sign kept, so the accumulator runs from -255 to 255. ! on an empty queue leaves JavaScript's undefined, which is not 0, never above 0 and prints as a zero byte. . gives 0 at the end of the input.

Example

The HI program.

The HI program. It puts 10 and 0 in the queue, then adds 7 to the second ten times while counting the first down. 70 and 2 make H, and one more makes I.

The cat reads and prints until the end of the input.

Expected: hello

The if-else prints a character it reads that is not 0. The specification says it prints H otherwise, but the else branch opens with ! on an empty queue, and the specification's own interpreter then prints a zero byte.

Expected: a

Patterns it teaches

Further

Queue-based

Write your own in Run Convert a program from @!+-()

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: u40-21-2b-2d-28-29.

Command line

shib run u40-21-2b-2d-28-29 -e '.(,.)' --input 'hello'
shib manual u40-21-2b-2d-28-29

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/u40-21-2b-2d-28-29.js

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

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