Premier
The code runs once for every character of the data. To loop, add data; to branch, rewrite the code.
Conor O'Brien · Turing complete: unknown · ●●○ moderate
Tested with 7 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
A Premier program has two parts. The first line is the code and everything after it is the data. The code runs once per character of the data, with that character pushed on the stack, and at the end of each round the top of the stack is printed. So a program whose first line is empty prints its data back: the Hello World on Try It Online is a blank line and then Hello, World!.
Read the story
There are no loops or jumps. A program loops by adding to its own data, which gives it more rounds, and changes what it does by putting text before or after its own code, which takes effect in the next round.
The machine
| Code | Does |
|---|---|
12 'x `x "…" […] | Push a number, a character, its code, a string | |
+ - * / % | Arithmetic, or join, repeat and format strings; failure gives 0 |
= ~ | 1 or 0 for equal, not equal |
@ : \ r C b d | Drop, duplicate, swap, reverse, clear, rotate n, duplicate n |
_ c o s l f L | Negate or reverse, to character, to code, next, length, first n, all but n |
n O p I | Print, print with a newline, print as a character, no output this round |
i < > Q $ A ^ | Data position and moving it, push, replace or add to the data |
P T a v # | Push the code, put text before or after it, replace it |
g G S | Read a line onto the stack, a line or everything into the data |
e | Exit |
A first line that starts with a number N takes N more lines as code. The reference is premier.rb in github.com/ConorOBrien-Foxx/Premier. This implementation leaves out |…|, which runs code over each character, and the two commands that wait for a key press.
Example
The second shifts each letter of HAL one place up the alphabet.
The second shifts each letter of HAL one place up the alphabet. The third turns off the implicit output and prints each character with a newline instead. The last shows the rule about numbers. The first line starts with 3, so 3 is not code: the code is 4*n10c, and 4* has nothing to multiply.
Patterns it teaches
- Self-modifying code:
T,a,vand#rewrite the code for the next round. - Code as data:
Pputs the code on the stack as a string.
Further
- The reference interpreter, in Ruby
See also
Also in Strange time
Write your own in Run Convert a program from Premier
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: premier.
Command line
shib run premier -e 'I
abc'shib manual premierSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/premier.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language