esolang

Brainfunc

Brainfuck without loops. A program repeats only by calling its own functions.

2020 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, world!

The idea

Brainfunc is a brainfuck variant from 2020 with functions in place of loops. Every ) ends a function, and the functions are numbered from 0 in the order they stand. The run starts after the last ). A call is ^ with a number in base 7, and it happens only when the current cell is not

Read the story
  1. So a loop is a function that calls itself, and the cell decides when it stops.

There is no -, and no . or , either. Cells only go up, and wrap from 255 to 0. One command, %, does both input and output. It reads a character when the cell is below 32 and not 10, and prints the cell otherwise.

The machine

CommandDoes
+Add 1 to the cell
> <Move right or left
%Read a character if the cell is below 32 and not 10, else print the cell
^nCall function n, written in base 7, if the cell is not 0
)End a function and return

The tape has no end either way. The end of the input reads as 10, the value the specification gives for no input.

Example

Hello world.

Hello world. Its three functions add 70, 5 and 10, and the main program after the last ) builds each letter from them, one or two cells at a time. It ends on a 10, so it prints a line feed last.

The truth machine reads a character and prints it, then adds 208. That brings the 48 of a 0 round to 0, so ^0 does not call and the run ends. A 1 becomes 1 instead, and the call reaches a function that prints it and calls itself for ever.

Expected: 0

The cat, %%>+^0)+^0, echoes each character from a new cell and never ends. At the end of the input % reads a 10, prints it as a line feed, and the calls go on. The specification also prints every character from 32 to 255 with a function that prints the cell, adds 1 and calls itself until the cell wraps round to 0.

Patterns it teaches

Further

Brainfunc builds on Brainfuck.

Brainfuck derivatives

Cell-based

Write your own in Run Convert a program from Brainfunc

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: brainfunc.

Command line

shib run brainfunc -e '%+^0)+++++++)+++^1%+^1^1^1^0'
shib manual brainfunc

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/brainfunc.js

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

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