esolang

Transortogonal Polymorphism

Only parentheses. Every list is a path through objects that each hold endless other objects.

Hakerh400, 2020 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: 0

The idea

Hakerh400 made Transortogonal Polymorphism in 2020. Memory is a graph of objects. Every object has endlessly many keys, every key is itself an object, and every key at first leads to an object of its own. A list of parentheses is an address, read from the root R. () is R itself, (()) is R[R], the root read at the key that is the root, and (A B C) is R[A][B][C] with each of A, B and C an address again.

Read the story

There are four instructions, and the program is nothing but lists. A list that is no instruction is replaced by its own content twice, so even the syntax unfolds as it runs.

The machine

InstructionDoes
() x yPut the object at y at the address x
(()) x yThe same, if the next input bit is 1
((())) x yPrint 1 if x and y hold the same object, else 0
(()()) x y (z)Run z while x and y hold the same object

Missing arguments at the end are (). Input and output are bits. Each input bit comes after an extra 1, and past the end every bit is 0, so a program reads a 1 for "more" and then the bit itself.

Identifiers are shorthand for lists. One the program has not seen before takes the list after it as its value and stays in place as that list. \name makes a longer one. The specification's readable programs define their names inside one harmless first instruction, which gives the root a fresh object, and after it they unfold to exactly its programs in parentheses.

Example

R[R] starts as an object of its own, so it differs from R and the first program prints 0.
Expected: 1

R[R] starts as an object of its own, so it differs from R and the first program prints 0. The second first puts R at R[R], and then they are the same.

The cat, in parentheses only. It reads the 1 that says more input follows, then the bit, prints it, and loops.

Expected: 1011

The specification also has a reverse, which turns 1101 into 1011, and a binary increment, which turns 1011 into 1100. Both build linked lists out of fresh objects.

Patterns it teaches

  • Turing tarpit: two characters, four instructions and a graph of objects.

Further

Also in Turing tarpits

Write your own in Run Convert a program from Transortogonal Polymorphism

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run transortogonal-polymorphism -e '()()(
  R()
  A(R)
  B(A)

  0(AA)
  1(AB)
  x(BA)

  \set ()
  \in (())
  \out ((()))
  \loop (()())
)

\set x 0
\in x 1

\loop x 1 (
  \set x 0
  \in x 1

  \out x 1

  \set x 0
  \in x 1
)' --input '0110'
shib manual transortogonal-polymorphism

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/transortogonal-polymorphism.js

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

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