We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Flatline

From Esolang
Jump to navigation Jump to search
This article is not detailed enough and needs to be expanded. Please help us by adding some more information.

Flatline is a language invented by Tristan Parker which is based on BF and has some elements of a Turning tarpit.

Variant

There are two flavors of Flatline, a 4 operand OISC and a zero operand BF variant.

OISC

The OISC variant takes the following operands:

OISC Commands
Operand Description
A Added to the current cell in a BF-like tape
B Added to position of a BF-like tape-head
C Added to the code-position (jump) if the current cell (after application of A and B) is 0
D Added to the code-position (jump) if the current cell (after application of A and B) is non 0

Negative numbers have to be allowed for the jumps to work right, but other than that the environment is nearly identical to that of BF.

BF Variant

The BF variant is essentially the same, but uses strings of + and - separated by ; instead of numbers. That said, it has a more complex actual definition.

It has a BF style memory layout, with pointers C and D and tape *D[30000]. It also has a register R, which is always 1, 2, or 3, and a register A which can be any integer value within reason (reason being implementation dependent).

Each cycle, C points to a new character. If it is + or -, A is incremented or decremented accordingly.

If it's ;, the subsequent behavior depends on R:

  • If it's 1, then it adds A to the cell pointed to by D (covering BF's + and -)
  • If it's 2 then it adds A to D (covering BF's ;lt and ;gt)
  • If it's 3, it checks if A is positive or negative
    • If A is negative it adds A to C iff the cell pointed to by D is not zero
    • If A is positive then A is added to C iff the cell pointed to by D is zero

Then, finally, the ';' increments R.

The initial state of the tape is taken from input, and the final state of the tape after the program halts (running out of commands, just like BF) is sent to output, thus defining away the need for ,. while being Turing-complete.

Examples

Add Two Numbers

This code should take two ASCII values, adds them, and outputs the result. an input of !! should return B. The equivalent BF code would be ,>,[-<+>]<..

This was the first attempt, written by Tristan Parker:

;+;;-;-;+++++++++;+;+;-----

This was the second attempt, written by someone else, with spaces added for clarity (with regards to the BF commands in the BF-to-Flatline conversion below):

;+;; ;;+++++++++++++++; -;;; ;-;; +;;; ;+;; ;;---------------;

This is an optimized version of the second attempt:

;+;++++++; -;-;; +;+;------;

Computational Class

It was indicated that you can easily translate from Brainfuck to the OISC version:

BF-to-OISC Convertor
BF A B C D
+ 1 0 1 1
- -1 1 1 1
> 0 1 1 1
< 0 -1 1 1
[ 0 0 x+1 1
] 0 0 1 1-x

x is the number of characters between [ to the matching ] plus 1. For example, [->+<] has x=5.

This is the equivalent for the BF version:

BF-to-Flatline Convertor
BF Flatline
+ +;;;
- -;;;
> ;+;;
< ;-;;
[ ;;+{y*3};
] ;;-{y*3};

x is the number of characters between [ to the matching ] as before. You repeat the character before the braces the number of times within the braces. For example, +{5} would be +++++.

External resources