Promo

From Esolang
Jump to: navigation, search

Promo (Procedural Model) is a programming language based on Brainfuck created by structuresend (Alex Costea), meant to be an easy and powerful model of computation. It uses 6 characters and 8 commands.

Like Brainfuck, it operates on a list, however the list is infinite in both directions and all numbers on it can get arbitrary big. Unlike Brainfuck, it takes only one (or zero) natural numbers as input and returns one number as output. The input is written in the initial cell, and the value of the final cell is considered the output. Also unlike Brainfuck, every program is valid (calls to non-existing functions are simply ignored).

The first 4 characters have the same meaning as in Brainfuck. Every character not in "+-<>#@" is ignored.

Command Meaning
+ add 1
- remove 1
> move right by 1
< move left by 1
# and @ when started with #, call the function corresponding to the number in binary written by # as 1 and @ as 0. Example: #@#@ calls function 10. Calls are not made if the current cell is 0.
@ when followed by a string containing only "@", do a dynamic call. This means:
  1. let k = current cell
  2. move to the right as many times as there are @'s
  3. if the current cell is not 0, call function k
  4. move left by the same amount
+- separates functions between then, starting with function 0 (which is called automatically at the beginning), 1, 2, 3...
>< Only when written as the first 2 characters, take a number as an input. If omitted, input will automatically be considered 0.

Examples

This program calculates 2^n of a given number (or loops forever for negative inputs).

 ><>+<#>+--#>#@<+--#@++

As the only output is a number, a traditional Hello, World! is impossible (unless encoded as a Base 256 number).

Cat program

 ><

Quine (kinda cheating?)

 0

Busy Beaver lower bounds

BusyBeaver(n) is defined as the biggest number that can be outputted by a program that takes no output with n characters. Those are the current lower bounds for it, and some examples:

n BusyBeaver(n) Example
0 0 [the empty program]
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10 ++++++++++
11 12 +#+#+--#+++
12 21
13 39
14 84
15 155
16 340
17 780
18 1554
19 9330
20 2391483
21 2^256-2 ++#+#+#+--#+#@+--#@++
22 > 10^1000000
23 > 10^10^76

Compiler

There's an online compiler here, which first converts the program to an optimized intermediate language (BBCL), then runs it in the browser. The source code (as well as more information about the language) can also be found there. I might eventually also write a BBCL to LLVM compiler.