esolang

Folders

A program is a tree of empty folders. Names are ignored and files are ignored, so the whole program takes up zero bytes.

Daniel Temkin, 2015 · Turing complete: yes · ●●○ moderate · esolangs.org

The idea

Daniel Temkin made Folders in 2015. The code is not in any file. It is in the shape of a directory tree: how many sub-folders each folder has, and in what order. Folder names can be anything, so a program can look like an ordinary, boring set of project folders.

Read the story

Because folders hold no data, a Folders program reports a size of 0 bytes, however large it is. It is camouflage at the level of the file system: nothing to read, nothing to scan, only structure.

An earlier dialect used folder names as commands. It was dropped; the current language reads structure only.

The machine

Folders are read in alphabetical order of their names. Each command is a folder whose first sub-folder says what it is (by its number of sub-folders) and whose later sub-folders hold the operands.

Folders in the first sub-folderCommand
0if (expression, then a folder of commands)
1while (expression, then a folder of commands)
2Declare a variable (type, name)
3Let: assign (variable, expression)
4Print (expression)
5Input (variable)

Expressions work the same way:

CountExpressionCountExpression
0Variable5Literal value (type, then value)
1Add6Equal to
2Subtract7Greater than
3Multiply8Less than
4Divide

Types: 0 int, 1 float, 2 string, 3 char. A literal value is written in hexadecimal: each hex digit is a folder of four folders, where a folder that contains a sub-folder is a 1 bit and an empty one is a 0 bit.

Example

The shape of a program that prints one character, drawn as a tree.

The shape of a program that prints one character, drawn as a tree. Names are placeholders, chosen so that alphabetical order is the order shown:

prog/
  a/                      one command
    a/ [a b c d]          4 folders: print
    b/                    the expression
      a/ [a b c d e]      5 folders: a literal value
      b/ [a b c]          3 folders: of type char
      c/                  the value, hex digits in order
        ...               groups of four folders, full = 1, empty = 0

This is illustrative. The specification does not fully pin down the bit order inside a group, or how many hex digits a char takes, so check the reference implementation before building one by hand.

A program that builds this tree with a script, then runs it, is the honest way to work: nobody writes Folders by clicking "New folder".

Patterns it teaches

  • Camouflage: the program does not look like anything, because it has no content. The only "text" is a shape.
  • Encoding tricks: a tree of counts, with bits written as "has a child" or "has none". It is Unary-like in spirit: the number of things is the message.

Try this

  1. Draw the tree for a while loop whose body prints a variable.
  2. Write a small Node script that turns a nested list like [4, [5, [3], [...]]] into real folders.
  3. Hard: write a Folders interpreter that reads a directory tree. (fs.readdirSync and a sort are most of the work.)

Further

Non-textual

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