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
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
| Command | Does as Python does |
|---|---|
print input intinput | print(x), input(), int(input()) |
add sub mul div mod pow | x+y, x-y, x*y, x//y, x%y, x**y |
and or xor not lsh rsh neg | Bitwise and, or, xor, not, shifts, minus |
eq neq leq geq lt gt | A comparison as 1 or 0 |
lnt lnd lor | Logical not, and, or as 1 or 0 |
if | y if x else z |
for loop | The list of x for i from y to z, and that i |
while | Run y while x is true, then give 0 |
str num index | chr(x), ord(x), x[y] |
comma | The list of its arguments |
func arg | Define 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.
The truth machine compares a line of input with the string 1. On 0 it prints 0; on 1 it prints 1 forever.
The cat prints every line it reads. Like Python's input(), it stops with an EOFError at the end of the input.
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
See also
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 objlangSource
- 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