esolang

Dirty

A two-dimensional language where a string literal reads differently depending on which way the pointer enters it.

Ourous, 2012 · Turing complete: unknown · ●●○ moderate · esolangs.org

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

Run it

Expected: Hello, World!

The idea

Dirty is a recreational language by Ourous, written in Clean in the repository Ourous/dirty. Its README calls it a two-dimensional, lazily evaluated language. The program is a grid of characters from its own code page of 256 symbols, and an instruction pointer walks over it. The file charset.txt plans an instruction for almost every symbol, from arithmetic and set operations to bouncing off diagonal walls.

Read the story

The interpreter is unfinished. Its instructions for reading input stop with an abort, and many list and string instructions are stubs. This implementation follows the parts that run.

esolangs.org has a page called Dirty, but it describes an older and unrelated language by another author.

The machine

The grid is the program split into rows at each newline, with short rows padded by spaces. Without a start symbol the pointer begins at the top left, heads east and the program ends when the pointer leaves the grid. With a start symbol such as ⍄ it begins there, and the grid wraps around at its edges.

A string literal is read from its quote cell in the direction the pointer is moving, up to the next quote. So 'olleh' read from the right gives hello. The text goes on the left stack and the pointer continues from the closing quote.

SymbolDoes
'…'Push the text met in the direction of travel
‼Print the top of a stack as characters
▲ ▶ ▼ ◀Turn the pointer
⍓ ⍄ ⍌ ⍃Start here, heading that way
■End the program

Example

In the second program ‼ first finds nothing to print.
Expected: hello

In the second program ‼ first finds nothing to print. The pointer pushes olleh, turns at ◀, and on the way back the same quotes give hello, which ‼ then prints before the pointer leaves the grid.

Expected: ab

The pointer starts at ⍄, wraps around to the left edge, prints ab and stops at ■.

This implementation is a subset. It has the five kinds of symbol above. Number literals, arithmetic and every other instruction stop the run with a reason.

Patterns it teaches

Try this

  1. Print your name with the text written backwards.
  2. Print a word written down a column.
  3. Hard: print two words from one literal by reading it both ways.

Further

Stack-based

Write your own in Run Convert a program from Dirty

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run dirty -e ''\''ab'\''‼■⍄'
shib manual dirty

Source

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

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

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