esolang

Sortle

A sorted list of named expressions. Each one renames itself, and the last name left is the output.

Scott Feeney, 2005 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: hello

The idea

Scott Feeney made Sortle in 2005, from the idea of insertion sort. A program is a list of expressions, each with a name, kept in ASCII order. The first one runs, and its result becomes its new name, so it moves to a new place in the list. Then the next one runs.

Read the story

Expressions have no side effects. Renaming to the empty string deletes an expression, and renaming to the name of another one replaces it. When only one expression is left, its name is printed and the program ends. That is the only output and the only way to stop. The names are also the only memory, and expressions read each other's names with a small regex operator.

This implementation leaves that operator out, because its specification is not available. Without it an expression cannot see the others, so this is a subset.

The machine

TokenDoes
"text" 42Push a string or a number; \0a is a hex escape
+ * / %Whole-number arithmetic on the top two
^The greater of two strings
~Join two strings
$The later of two strings, or the one that is not empty
?Regex matching on names; not implemented

A number becomes a name in decimal, and 0 becomes the empty string.

Example

With one expression nothing runs.

With one expression nothing runs. The program prints its name at once.

hello sorts before quit, so it runs first and renames itself. Then quit deletes itself, and the new name is all that is left.

Expected: hello, world

Patterns it teaches

Further

String-rewriting paradigm

Write your own in Run Convert a program from Sortle

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run sortle -e 'hello := ""'
shib manual sortle

Source

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

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

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