esolang

ObCode

Everything is a list of lists. A number is how long a list is, and an instruction is a list with a particular shape.

Challenger5, 2016 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 4 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: A

The idea

Challenger5 made ObCode in 2016. Its only data type is the object, a list of zero or more objects, written in parentheses. () is the empty object, (()()()) an object holding three empty ones. A program is one object, and each of its elements is run as an instruction, recognised by its shape.

Read the story

Numbers are lengths. To print H a program pushes an object of 72 empty objects and runs OUT. Memory is a stack of stacks. USING opens an object up as a new stack to work inside, and END closes the current stack back into a single object. A loop runs while the current stack is not empty, so counting down means popping elements off a stack.

The machine

ObjectNameDoes
()NOPNothing
(())PUSHPush the next element as data
(()()) ((())())STORE LOADPop into the register; push the register
(()(()))WHILEPop a body; run it while the current stack is not empty
((())(())) ((()))USING ENDOpen an object as a new stack; close the stack into an object
((()()))SWAPSwap the top two
(()()()) ((())()())OUT INPrint a length as a character; read a character as a length
(()()(()))CATJoin two objects
((()())())DEFPop a, pop b; from now on the instruction a runs b

Everything except parentheses is a comment.

Example

The second is the cat from esolangs.org.
Expected: cat!
Expected: 0

The second is the cat from esolangs.org. It reads a character, opens it as a stack, and loops until a character of length 0, the end of the input. The third redefines () to mean "double the top object", then doubles 3 four times to get 48, the code of 0.

Further

Ideas it shows

Stack-based

Write your own in Run Convert a program from ObCode

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: obcode.

Command line

shib run obcode -e '(((())()())(()()()))' --input 'xyz'
shib manual obcode

Source

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

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

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