esolang

0(nop^)

Functions have numbers for names, and ^ is the only way to jump.

Turing complete: unknown · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, World!

The idea

0(nop^) is a stack language with one form of flow control. Text written between parentheses is saved as a numbered function, and ^ runs the function whose number is on top of the stack. A saved function ends in ^ itself, so when it is done it hands over to whatever number is on top. A loop is a function that leaves its own number there; 0 ends the chain.

Read the story

The specification lists its commands in one line each and points to an interpreter in C that is not in the specification. This implementation runs the commands the specification makes clear and leaves out the rest.

The machine

CommandDoes
49Push a number
+ - * / % < > =Arithmetic and comparison on the top two
_ $ \ @Negate, duplicate, swap, rotate three
. ,Print a character; read one
( ... ^ ... )Save the text before ^, with the ^, as the function numbered by the top
( ... " ... )Save the text as the string numbered by the top
n)Inside the parentheses, a number before ) runs that function
^Run the function numbered by the top; above 32, run that character as a command
` | Print the string numbered by the top

Left out are ~, a sine table the specification does not give, ? for random numbers, the pointers &, ! and #, | for reading a line, and [ ] for files. The specification's self-interpreter needs the pointers, so it does not run.

Example

The Hello World saves everything up to ", the line break too, as string 1 and prints it with ` .

The Hello World saves everything up to ", the line break too, as string 1 and prints it with ` .

The cat saves ,.1^ as function 1 and runs it. Each pass reads a character, prints it and pushes 1, so the ^ at its end runs function 1 again. The end of the input ends it.

Expected: meow

The quine keeps its shared text as string 1. Line 2 saves the same text as function 2 and runs it, and the function prints 1(, the string, "), a line break, 2(, the string again and ^2) as character codes. Then 0^ ends it.

Expected: 1(49.40.1`34.41.10.50.40.1`94.50.41.0") 2(49.40.1`34.41.10.50.40.1`94.50.41.0^2)

Patterns it teaches

  • Stack machines: the stack also chooses which function runs next.
  • Code as data: functions and strings are the same saved text.
  • Quine: one text, kept once as a string and once as the function that prints it.

Further

Also in Functional and concatenative

Write your own in Run Convert a program from 0(nop^)

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: 0-nop.

Command line

shib run 0-nop -e '1(,.1^1)' --input 'meow'
shib manual 0-nop

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/0-nop.js

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

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