Introduction to esolang design/Data models

From Esolang
Jump to navigation Jump to search

Choosing a data model is an important part of making an interesting Esolang. This article forms a compilation of some popular data models.

Primary Data Model

The scalar

The simplest data model is a single scalar variables that holds data. Usually, these need Gödel numbering to be Turing-complete if that is indeed the goal.

The map

Most normal languages use a map to represent their data (though they may not use that once compiled) that maps strings (which represent variable names) to values. These are usually not used in esolangs, however, because they seem too traditional; however they can be used if the language uses something else for the eso- factor.

The stack

Stacks are potentially the most popular data model used in original Esolangs. They work simply: Data can be "pushed" upon the stack and "popped" off of it. Operations pop data off of the stack and manipulate them, then push the return value(s) if available. Stacks are easy to implement and can be manipulated, making them popular for Esolangs.

The queue

Queues are like stacks, but FIFO instead of FILO (as stacks are), meaning that data enqueued has to wait for data enqueued before it to be dequeued before it can be dequeued. Because it behaves like a stack but is harder to manipulate, it is popular for esolangs.

The deque

Deques are a hybrid of queues and stacks.

The tape

When including derivative languages, tapes are likely the most popular data model by far due to the vast number of Brainfuck derivatives. They are represented as a right- or both-infinite array of "cells", where each cell holds a value. Accompanying the tape is one or more pointers that declare what parts of the tape are currently active, potentially including a meta-pointer which declares the primary pointer. Each pointer has a "left" and "right" (or only one of the two) command that makes it move along the tape.

The n-tape

An n-tape is a tape generalized to n dimensions. A normal tape is a 1-tape.

The trape

The trape is like a tape, but is represented by a tree instead of a list. Usually, the tree has a fixed number of children for each node.

The tape ring

A tape ring is a variant on a normal tape where one side connects to the other, so as the pointer moves along the tape it eventually returns to its original location. This is represented easily by a deque.

The growable tape ring

Most tape rings are growable, but some are not; a tape ring is growable if the length of the tape (number of times the pointer must go in a certain direction to return to a square) can be changed by adding new cells. This is represented easily by a deque where new values are added when a cell is inserted.

The Möbius tape ring

A tape ring is Möbius if it is hypothetically represented by, when one end of the tape connects to the other, there is a half twist meaning that the pointer can traverse to the opposite side of a cell. This is most noticeable if, for example, the cells are deques and which of the sides of the deque is accessed depends on the side of the cell the pointer is on. A growable Möbius tape ring is, of course, possible.

The treeng

A treeng is a hybrid of a trape and a ring: A tree which's leaves connect back to the root node. Growable trings are possible, of course, along with Möbius variants (presumably)

The registry

Registries allow any data held in them to be accessed at any time by having each index be a value.

The datagraph

A datagraph is a graph where the nodes store data.

The pointed graph

A pointed graph is a graph like a datagraph where a pointer or pointers declare an active node(s). These are typically directed graphs.

The graph (rewriting)

A graph can be rewritten, so sometimes that is used for a data model.

The tuple

A data model is a tuple if there are multiple different data models stored together, each one with its own set of commands or with a pointer to which one is active.

The nest

A data model is a nest if one data model is used within another (e.g. a tape of stacks). They are characterized quite simply by being a data model where each individual datum is another data storage mechanism. These can get quite strange, e.g. a stack of maps. There is no limit on how deep one of these can nest.

Secondary Data

Sometimes, a secondary data storage mechanism is included for the purposes of data transfer or other reasons. Sometimes, this is called an accumulator

The scalar accumulator

A scalar accumulator is the simplest type of accumulator: a single scalar variable that stores a single piece of data. These tend to get clobbered a lot.