esolang

ObjLang

A program is a Python dictionary, saved in Python's binary marshal format.

None1, 2024 · Turing complete: conjectured · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, World!

The idea

None1 made ObjLang in 2024. It has no text syntax at all. A program is a nested Python dictionary written out with Python's marshal module, so the source file is binary. Each dictionary has one key, the command, and its value is the list of arguments. An argument can be another dictionary, so a program is a tree of calls, a little like Lisp built from Python's own data. The specification shows each program in base64, and this implementation takes it that way.

Read the story

The values are Python's int, str and list, and they behave as they do in Python. Integers have no bound, div is floor division and print ends with a line feed.

The machine

CommandDoes as Python does
print input intinputprint(x), input(), int(input())
add sub mul div mod powx+y, x-y, x*y, x//y, x%y, x**y
and or xor not lsh rsh negBitwise and, or, xor, not, shifts, minus
eq neq leq geq lt gtA comparison as 1 or 0
lnt lnd lorLogical not, and, or as 1 or 0
ify if x else z
for loopThe list of x for i from y to z, and that i
whileRun y while x is true, then give 0
str num indexchr(x), ord(x), x[y]
commaThe list of its arguments
func argDefine a command; read one of its arguments

The arguments of a command are worked out first, left to right, except for if, for, while and func, which decide when theirs run. A list written in the program is a value as it stands, and its commands do not run; comma is the way to run several.

Example

The Hello, World! is the dictionary {"print":["Hello, World!"]}.

The Hello, World! is the dictionary {"print":["Hello, World!"]}.

The A+B problem adds two lines of input as numbers.

Expected: 7

The truth machine compares a line of input with the string 1. On 0 it prints 0; on 1 it prints 1 forever.

Expected: 0

The cat prints every line it reads. Like Python's input(), it stops with an EOFError at the end of the input.

Expected: hi

The last program defines fib with func and prints fib(1) to fib(100) with for. The specification warns it is slow, as each term costs as much as the two before it together.

Patterns it teaches

  • Code as data: a program is a data structure of the host language, stored in its binary format.

Further

Binary

Functional paradigm

Write your own in Run Convert a program from ObjLang

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run objlang -e 'e9oFcHJpbnRbAQAAAPoNSGVsbG8sIFdvcmxkITA='
shib manual objlang

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/objlang.js

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

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