Longplayer
Longplayer is a language loosely based on the music that bears its name. It implements a control flow scheme that the author believes to be entirely unique, based on multiple permutations of different command steps.
Overview
Code is given in the form:
<number of tiers> <instructions>
The instructions are executed by each tier simultaneously, as if they are multiple threads. Upon successfully executing the instructions a tier will begin the instructions again.
What makes this language interesting is that each tier takes a different length of time to execute: the second tier executes 2 instructions in the time it takes the first to execute 3, the third can do 2 instructions in the time it takes the first to do 5, and so on through all the primes. Thus the speeds are in the ratio 2:3:5:7... This is not quite how Longplayer music works, but I adapted it in an attempt to force the programmer to think in more interesting ways.
If two or more tiers would execute simultaneously, the tier with lowest number executes first. An instruction also produces different effects depending on what tier it is on, as described below.
Instruction set
The instructions operate on an unbounded tape, heavily inspired by brainfuck. Each tier operates on the same tape.
If there are n tiers in total, and the mth tier executes an instruction, take the first n primes apart from the mth prime. Let the product of these primes be p in the following table:
Instruction | Effect |
---|---|
+ | Increment cell by p. |
- | Decrement cell by p. |
< | Move p cells left. |
> | Move p cells right. |
. | Output value in cell divided by p as character |
, | Input character, convert to number and store number times p |
! | Skip, see below. |
? | Skip if cell is 0, see below. |
: | Halt the program (there is no other way to do this) |
* | NOP |
A skip will treat all instructions up to and including the next instruction on that tier as *. This takes effect across tiers: if one tier is executing a skip, instructions will be ignored until it is finished. This makes it possible to skip a skip, which makes conditional stuff easier (hopefully). Notice that lack of square brackets makes it impossible to skip multiple instructions without this functionality.
Examples
Cat program
1 ,?!:.
Some simple programs like this can be done on just one tier. Remember that the instructions automatically loop after executing.
Truth test
1 ,.------------------------------------------------?!:++++++++++++++++++++++++++++++++++++++++++++++++!
Again, just one tier.
Computational class
If someone finds a way to move the instruction pointer backwards, then you can translate BF to Longplayer, thus making it turing complete