esolang

Brainf with functions

Brainfuck plus two characters, enough to name a piece of code and call it again.

2023 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: HIWORLD

The idea

Brainf with functions is brainfuck with : and ; added, from 2023. X: starts a function named by the symbol before the colon and ; closes it. After that, the symbol X on its own runs the body.

Read the story

A definition takes effect when the run reaches it. So a function can be defined again, and a definition inside a loop only happens when the loop runs. The second truth machine uses that to pick what P will do.

The machine

CommandDoes
> <Move the pointer
+ -Add or take 1
. ,Print the cell; read a byte into it
[ ]Brainfuck's loop
X: ... ;Define the function X
XCall X

A name is any character that is not whitespace and not one of the commands. A name with no function yet does nothing. Cells are bytes that wrap, and , gives 0 at the end of the input.

Example

o adds 8.

o adds 8. c moves the cell into the one on its left. f adds 7 tens to the cell next door and moves them back, so it adds 70. Seven calls to f put 70 in seven cells, and small changes turn them into H, I, W, O, R, L and D.

Expected: 0

C sets a cell to 48, the code of 0. The program takes 48 off the input, so a 0 leaves 0 and a 1 leaves 1. Only a 1 enters the loop, where P is defined again to print 1 forever. On 0 the first P stays and prints one 0.

Patterns it teaches

Further

Brainf with functions builds on Brainfuck.

Brainfuck derivatives

Write your own in Run Convert a program from Brainf with functions

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: brainf-with-functions.

Command line

shib run brainf-with-functions -e 'A:++++++++;
B:++++++;
R:[-];
C:R>RA[<B>-]<;
C
>,
<[>-<-]>
[>C+.R<]
C.' --input '0'
shib manual brainf-with-functions

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/brainf-with-functions.js

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

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