Brainfuck$

From Esolang
Jump to navigation Jump to search

Brainfuck$ (sometimes called Brainfuck with Buffer, although it doesn't really have a buffer at all) is an esoteric programming language derived from Brainfuck, which features only the addition of a stack - which is used to ensure that there will be no data corruption when performing certain operations that require loops - and two new commands for I/O that deal with absolute numbers (meaning an input of '3' will not refer to the ASCII value of '3', but to the number itself).

Brainfuck$ introduces six new "one char" commands:

Command Description
#
Copies the byte on the current cell to the top of the stack.
$
Removes a byte from the top of the stack and places it in the current cell.
;
Gets numeric input (instead of char input).
:
Gives numeric output (instead of char output).
(
A special kind of loop, much like [, which basically says: Loop n times, where n is the value of the last element on the list when this character is interpreted (it doesn't matter if the top value changes later).
)
The closing of the list-loop, as in ].

It should be noticed that Brainfuck$ merely extends on the original language, so it still has the primary eight commands.

The most obvious difference between Brainfuck and Brainfuck$ is the classic example of cell copying. It is impossible to make a Brainfuck program which copies the content of a cell without eventually destroying the contents of another cell. For example, if we were to copy the content of cell 1 to cell 2, we'd have to use cell 3 as the loop index, and it's previous contents would be lost. The actual code would be performed this way:

  1. Clear the contents of both cells 2 and 3
  2. Copy the content of 1 to both 2 and 3. This will erase cell 1.
  3. Copy the content of cell 3 to cell 1, therefore erasing cell 3.

This compiles as the following brainfuck program:

>[-]>[-]<<[->+>+<<]>>[-<<+>>]<<

However, Brainfuck$ allows the programmer to not only save the contents of all cells, but to also do so with a much cleaner code, which is:

#>$

In the above three-character-example, the value of cell 1 is copied to the end of the list, the pointer is moved to the following cell, and then the copied value is blit back into cell 2.

External resources

  • Currently, there is no compiler for Brainfuck$, but there is a language interpreter (requires java).