esolang

Brainfuck Encoded Concatenative Calculus

Brainfuck's eight characters, given to a calculus of quoted programs that rewrites itself from the left.

Olus2000, 2022 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 2

The idea

Olus2000 made Brainfuck Encoded Concatenative Calculus, or BECC, in 2022. It keeps brainfuck's characters and nothing of its machine. There is no tape. A program is one expression of quotations in brackets and operators between them, and running it means rewriting that expression, always the leftmost match first, until no rule fits.

Read the story

Everything else is built from four rules, as in the concatenative calculus. Swap is []<<+-, call is +-, and numbers and booleans are Church encoded.

The machine

OperatorRewritesAs
>[A][B]>[[A]B]
<[A][B]<[B[A]]
+[A]+[A][A]
-[A][B]-B, which then runs
.[A].nothing, and writes A
,,the next input

Only the top level is rewritten, never the inside of a quotation. An operator without the quotations it needs waits. The specification leaves input and output to the implementation and suggests Church numerals, where a number n is a quotation that runs the quotation before it n times. , reads a decimal number and . writes one, each on its own line.

Example

1 is [+-], and 1+ is [[+<+-]<+-+-]>.

1 is [+-], and 1+ is [[+<+-]<+-+-]>.

Expected: 2 0

The second program makes 2, puts 0, [[]-], after it and swaps them. Each . writes the quotation just before it, so 2 comes out first.

The cat reads numbers and writes them back until it reads a 0, which the end of input gives. Its first quotation is the pseudocode, dropped by []-; the loop is a fixed point made by the Y combinator, [[+>]<+-+-]>++-.

Expected: 3 5 0

Patterns it teaches

  • Concatenative: a program is a row of quotations, and joining rows composes them.
  • Combinators: cons, take, dup and k are enough to build the rest.
  • Lambda encoding: numbers and booleans are Church encoded.

Further

Also in Functional and concatenative

Write your own in Run Convert a program from Brainfuck Encoded Concatenative Calculus

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: brainfuck-encoded-concatenative-calculus.

Command line

shib run brainfuck-encoded-concatenative-calculus -e '[[+>]<+-+-]>++-'
shib manual brainfuck-encoded-concatenative-calculus

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/brainfuck-encoded-concatenative-calculus.js

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

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