Stroke

From Esolang
Jump to navigation Jump to search
Stroke
Paradigm(s) imperative
Designed by User:Ttulka
Appeared in 2024
Dimensions one-dimensional
Computational class Finite state automata
Major implementations Interpreter in JavaScript
Influenced Stroke+-
File extension(s) .🧠

Stroke, also {/|\}, is an esoteric structured programming language.

With only three instructions, it aims to be the simplest structured programming language ever.

It uses conditional loops and an unbounded number of binary variables, along with a command to flip their values.

Stroke is not Turing-complete as it can't represent an infinite set of bits, unlike its bigger brother Stroke+- which is.

Language

Stroke code consists only of stroke symbols /, |, \, and white spaces to separate them.

All other symbols are ignored.

Instructions

Instr Name Meaning
/ var Loop start Enters a new loop if var is non-zero
\ Loop end Jumps back to the matching loop start
| × n Flip value Flips the value of the variable n-1

All instructions and their attributes are separated by one or more white spaces.

The example code in Stroke:

| 
/ | 
  | 
  || 
\ 
|||

can be translated into the following pseudocode:

flip var0
while var0
  flip var0
  flip var1
flip var2

Optionally, the instruction for output ! may be implemented.

Variables

A Stroke program runs on a theoretically infinite tape of binary cells that are randomly accessible via variables denoted by consecutive vertical stroke symbols (|) in unary form starting from zero. For instance, | flips the variable indexed by 0, || flips the variable indexed by 1, ||| flips the variable indexed by 2, and so on.

A variable occurring in code directly after a loop start will be just read (and checked to be non-zero), while a variable anywhere else in the code will flip its binary value.

The binary tape can simulate integers of arbitrary size, e.g. 4-bit unsigned:

  variable index   0  1  2  3  4  5  6  7  8  9  10 11 ...
       bit index   3  2  1  0  3  2  1  0  3  2  1  0  ...
virtual variable   \   A    /  \   B    /  \   C    /  ...

Examples

The following examples operate on virtual 4-bit variables A, B, and C.

Empty program

The simplest program is the empty program:

nothing here

Infinite loop

As variable 0 is never reset, the program loops forever:

| / | \

Conditional branching

Conditional branching (IF) can be simulated via loops:

|||||||
/ | |
    |||||
    ||||||  
    ||||||| 
\
/ |||||| |||||| | \ 
/ |||||||       
    / || ||     
    |||||   
    ||||||       
    |||||||  
    \
    / |||||| |||||| || \
    / |||||||  
    / ||| |||  
        |||||     
        |||||| 
        |||||||
    \
    / |||||| |||||| ||| \
    / |||||||   
        / |||| ||||
        |||||   
        ||||||  
        \
        / |||||| |||||| |||| \
        ||||||| 
    \
    \
\
/ ||||| |||||  
  
  do something conditionally...

\

Equality check

Compares A and B bit by bit:

||||||||| ||||||||||||| ||||||||||| / | | ||||||||||||
/ ||||| ||||| |||||||||| |||||||||||| \ / ||||||||||
|||||||||| ||||| \ / |||||||||||| |||||||||||| |||||||||
||||||||||||| \ |||||||||| ||||||||||| \ / ||||||||||
|||||||||| | \ / ||||||||||| ||||||||||| / ||||| |||||
|||||||||| ||||||||| ||||||||||||| \ / |||||||||| ||||||||||
||||| \ \ / ||||||||||||| ||||||||||| / || || ||||||||||||
/ |||||| |||||| |||||||||| |||||||||||| \ / ||||||||||
|||||||||| |||||| \ / |||||||||||| |||||||||||| |||||||||
||||||||||||| \ |||||||||| ||||||||||| \ / ||||||||||
|||||||||| || \ / ||||||||||| ||||||||||| / |||||| ||||||
|||||||||| ||||||||| ||||||||||||| \ / |||||||||| ||||||||||
|||||| \ \ / ||||||||||||| ||||||||||| / ||| |||
|||||||||||| / ||||||| ||||||| |||||||||| ||||||||||||
\ / |||||||||| |||||||||| ||||||| \ / ||||||||||||
|||||||||||| ||||||||| ||||||||||||| \ ||||||||||
||||||||||| \ / |||||||||| |||||||||| ||| \ / |||||||||||
||||||||||| / ||||||| ||||||| |||||||||| |||||||||
||||||||||||| \ / |||||||||| |||||||||| ||||||| \ \
/ ||||||||||||| ||||||||||| / |||| |||| ||||||||||||
/ |||||||| |||||||| |||||||||| |||||||||||| \ / ||||||||||
|||||||||| |||||||| \ / |||||||||||| |||||||||||| |||||||||
\ |||||||||| ||||||||||| ||||||||||||| \ / ||||||||||
|||||||||| |||| \ / ||||||||||| ||||||||||| / ||||||||
|||||||| |||||||||| ||||||||| \ / |||||||||| ||||||||||
|||||||| \ ||||||||||||| \ \ \ \ \ ||||||||| |||||||||
    do something if equal...
/

Increment

The following program increments A:

|||||| / |||| |||| ||||| |||||| \ / ||||| ||||| |||||| /
||| ||| ||||| |||||| \ / ||||| ||||| |||||| / || || |||||
|||||| \ / ||||| ||||| |||||| / | | |||||| \ / ||||||
|||||| | \ \ / |||||| |||||| || \ \ / |||||| ||||||
||| \ \ / |||||| |||||| |||| \

Decrement

The following program decrements A:

||||| / |||| |||| ||||| \ / ||||| |||| / ||| ||| ||||| \
/ ||||| ||| / || || ||||| \ / ||||| || / | | ||||| \
/ ||||| | ||||| \ \ \ \

Addition

Having conditional branching, increment, and decrement intact, a program to add A and B is just a simple composition:

||||||||||| / ||||| ||||| ||||||||| |||||||||| |||||||||||
\ / |||||||||| |||||||||| | \ / ||||||||||| / |||||| ||||||
||||||||| |||||||||| ||||||||||| \ / |||||||||| ||||||||||
|||||| \ / ||||||||||| / ||||||| ||||||| |||||||||
|||||||||| ||||||||||| \ / |||||||||| |||||||||| ||||||| \
/ ||||||||||| / |||||||| |||||||| ||||||||| |||||||||| \
/ |||||||||| |||||||||| |||||||| \ ||||||||||| \ \ \
/ ||||||||| ||||||||| |||||||||| / |||| |||| |||||||||
|||||||||| \ / ||||||||| ||||||||| |||||||||| / ||| |||
||||||||| |||||||||| \ / ||||||||| ||||||||| ||||||||||
/ || || ||||||||| |||||||||| \ / ||||||||| |||||||||
|||||||||| / | | |||||||||| \ / |||||||||| |||||||||| | \ \
/ |||||||||| |||||||||| || \ \ / |||||||||| |||||||||| |||
\ \ / |||||||||| |||||||||| |||| \ ||||||||| / ||||||||
|||||||| ||||||||| \ / ||||||||| |||||||| / ||||||| |||||||
||||||||| \ / ||||||||| ||||||| / |||||| |||||| ||||||||| \
/ ||||||||| |||||| / ||||| ||||| ||||||||| \ / |||||||||
||||| ||||||||| \ \ \ \ ||||||||||| / ||||| ||||| |||||||||
|||||||||| ||||||||||| \ / |||||||||| |||||||||| | \
/ ||||||||||| / |||||| |||||| ||||||||| ||||||||||
||||||||||| \ / |||||||||| |||||||||| |||||| \
/ ||||||||||| / ||||||| ||||||| ||||||||| ||||||||||
||||||||||| \ / |||||||||| |||||||||| ||||||| \
/ ||||||||||| / |||||||| |||||||| ||||||||| |||||||||| \
/ |||||||||| |||||||||| |||||||| \ ||||||||||| \ \ \ \

Fibonacci sequence

|||||||||||||||| / |||||||||||||||| ||||||||||||||| / |||||
||||| ||||||||||||| |||||||||||||| ||||||||||||||| \
/ |||||||||||||| |||||||||||||| ||||| \ / |||||||||||||||
/ |||||| |||||| ||||||||||||| |||||||||||||| |||||||||||||||
\ / |||||||||||||| |||||||||||||| |||||| \ / |||||||||||||||
/ ||||||| ||||||| ||||||||||||| |||||||||||||| |||||||||||||||
\ / |||||||||||||| |||||||||||||| ||||||| \ / |||||||||||||||
/ |||||||| |||||||| ||||||||||||| |||||||||||||| \
/ |||||||||||||| |||||||||||||| |||||||| \ ||||||||||||||| \ \ \
/ ||||||||||||| ||||||||||||| ||||||||||||| / |||||||| ||||||||
||||||||||||| \ / ||||||||||||| |||||||| / ||||||| |||||||
||||||||||||| \ / ||||||||||||| ||||||| / |||||| ||||||
||||||||||||| \ / ||||||||||||| |||||| / ||||| |||||
||||||||||||| \ / ||||||||||||| ||||| ||||||||||||| \ \ \ \
|||||||||||||| / |||||||||||| |||||||||||| |||||||||||||
|||||||||||||| \ / ||||||||||||| ||||||||||||| ||||||||||||||
/ ||||||||||| ||||||||||| ||||||||||||| |||||||||||||| \
/ ||||||||||||| ||||||||||||| |||||||||||||| / ||||||||||
|||||||||| ||||||||||||| |||||||||||||| \ / |||||||||||||
||||||||||||| |||||||||||||| / ||||||||| ||||||||| ||||||||||||||
\ / |||||||||||||| |||||||||||||| ||||||||| \ \ / ||||||||||||||
|||||||||||||| |||||||||| \ \ / |||||||||||||| ||||||||||||||
||||||||||| \ \ / |||||||||||||| |||||||||||||| ||||||||||||
\ ||||||||||||||| / ||||| ||||| ||||||||||||| ||||||||||||||
||||||||||||||| \ / |||||||||||||| |||||||||||||| ||||| \
/ ||||||||||||||| / |||||| |||||| ||||||||||||| ||||||||||||||
||||||||||||||| \ / |||||||||||||| |||||||||||||| |||||| \
/ ||||||||||||||| / ||||||| ||||||| ||||||||||||| ||||||||||||||
||||||||||||||| \ / |||||||||||||| |||||||||||||| ||||||| \
/ ||||||||||||||| / |||||||| |||||||| ||||||||||||| ||||||||||||||
\ / |||||||||||||| |||||||||||||| |||||||| \ |||||||||||||||
\ \ \ \ ||||||||||||||| / | | ||||||||||||| ||||||||||||||
||||||||||||||| \ / |||||||||||||| |||||||||||||| | \
/ ||||||||||||||| / || || ||||||||||||| ||||||||||||||
||||||||||||||| \ / |||||||||||||| |||||||||||||| || \
/ ||||||||||||||| / ||| ||| ||||||||||||| ||||||||||||||
||||||||||||||| \ / |||||||||||||| |||||||||||||| ||| \
/ ||||||||||||||| / |||| |||| ||||||||||||| |||||||||||||| \
/ |||||||||||||| |||||||||||||| |||| \ ||||||||||||||| \ \ \
/ ||||||||||||| ||||||||||||| ||||||||||||| / |||| ||||
||||||||||||| \ / ||||||||||||| |||| / ||| ||| ||||||||||||| \
/ ||||||||||||| ||| / || || ||||||||||||| \ / ||||||||||||| ||
/ | | ||||||||||||| \ / ||||||||||||| | ||||||||||||| \ \ \ \
|||||||||||||| / |||||||| |||||||| ||||||||||||| |||||||||||||| \
/ ||||||||||||| ||||||||||||| |||||||||||||| / ||||||| |||||||
||||||||||||| |||||||||||||| \ / ||||||||||||| |||||||||||||
|||||||||||||| / |||||| |||||| ||||||||||||| |||||||||||||| \
/ ||||||||||||| ||||||||||||| |||||||||||||| / ||||| |||||
|||||||||||||| \ / |||||||||||||| |||||||||||||| ||||| \ \
/ |||||||||||||| |||||||||||||| |||||| \ \ / ||||||||||||||
|||||||||||||| ||||||| \ \ / |||||||||||||| ||||||||||||||
|||||||| \ / ||||||||||||| ||||||||||||| \ |||||||||||||||
/ | | ||||||||||||| |||||||||||||| ||||||||||||||| \
/ |||||||||||||| |||||||||||||| | \ / |||||||||||||||
/ || || ||||||||||||| |||||||||||||| ||||||||||||||| \
/ |||||||||||||| |||||||||||||| || \ / |||||||||||||||
/ ||| ||| ||||||||||||| |||||||||||||| ||||||||||||||| \
/ |||||||||||||| |||||||||||||| ||| \ / ||||||||||||||| /
|||| |||| ||||||||||||| |||||||||||||| \ / ||||||||||||||
|||||||||||||| |||| \ ||||||||||||||| \ \ \ \ |||||||||||||||
/ ||||||||| ||||||||| ||||||||||||| ||||||||||||||
||||||||||||||| \ / |||||||||||||| |||||||||||||| ||||||||| \
/ ||||||||||||||| / |||||||||| |||||||||| |||||||||||||
|||||||||||||| ||||||||||||||| \ / ||||||||||||||
|||||||||||||| |||||||||| \ / ||||||||||||||| / |||||||||||
||||||||||| ||||||||||||| |||||||||||||| ||||||||||||||| \
/ |||||||||||||| |||||||||||||| ||||||||||| \ / |||||||||||||||
/ |||||||||||| |||||||||||| ||||||||||||| |||||||||||||| \
/ |||||||||||||| |||||||||||||| |||||||||||| \ |||||||||||||||
\ \ \ / ||||||||||||| ||||||||||||| ||||||||||||| / ||||||||||||
|||||||||||| ||||||||||||| \ / ||||||||||||| ||||||||||||
/ ||||||||||| ||||||||||| ||||||||||||| \ / |||||||||||||
||||||||||| / |||||||||| |||||||||| ||||||||||||| \
/ ||||||||||||| |||||||||| / ||||||||| ||||||||| ||||||||||||| \
/ ||||||||||||| ||||||||| ||||||||||||| \ \ \ \ ||||||||||||||
/ |||| |||| ||||||||||||| |||||||||||||| \ / |||||||||||||
||||||||||||| |||||||||||||| / ||| ||| |||||||||||||
|||||||||||||| \ / ||||||||||||| ||||||||||||| ||||||||||||||
/ || || ||||||||||||| |||||||||||||| \ / |||||||||||||
||||||||||||| |||||||||||||| / | | |||||||||||||| \
/ |||||||||||||| |||||||||||||| | \ \ / ||||||||||||||
|||||||||||||| || \ \ / |||||||||||||| |||||||||||||| ||| \ \
/ |||||||||||||| |||||||||||||| |||| \ |||||||||||||| / ||||||||
|||||||| ||||||||||||| |||||||||||||| \ / |||||||||||||
||||||||||||| |||||||||||||| / ||||||| ||||||| |||||||||||||
|||||||||||||| \ / ||||||||||||| ||||||||||||| ||||||||||||||
/ |||||| |||||| ||||||||||||| |||||||||||||| \ / |||||||||||||
||||||||||||| |||||||||||||| / ||||| ||||| |||||||||||||| \
/ |||||||||||||| |||||||||||||| ||||| \ \ / ||||||||||||||
|||||||||||||| |||||| \ \ / |||||||||||||| ||||||||||||||
||||||| \ \ / |||||||||||||| |||||||||||||| ||||||||
\ ||||||||||||||| / ||||||||| ||||||||| |||||||||||||
|||||||||||||| ||||||||||||||| \ / |||||||||||||| ||||||||||||||
||||||||| \ / ||||||||||||||| / |||||||||| ||||||||||
||||||||||||| |||||||||||||| ||||||||||||||| \ / ||||||||||||||
|||||||||||||| |||||||||| \ / ||||||||||||||| / |||||||||||
||||||||||| ||||||||||||| |||||||||||||| ||||||||||||||| \
/ |||||||||||||| |||||||||||||| ||||||||||| \ / |||||||||||||||
/ |||||||||||| |||||||||||| ||||||||||||| |||||||||||||| \
/ |||||||||||||| |||||||||||||| |||||||||||| \ |||||||||||||||
\ \ \ \ \

Hello World

For computing "Hello World" the tape must be interpreted as a string. It can achieved by defining a binary alphabet:

Register Binary Decimal Interpreted
A 011010100 212 Hel
B 100101000 296 lo⎵
C 111101110 494 Wor
D 100001 33 ld

The following program sets the tape to 011010100100101000111101110100001 which corresponds to "Hello World":

|| ||| ||||| ||||||| |||||||||| ||||||||||||| |||||||||||||||
||||||||||||||||||| |||||||||||||||||||| |||||||||||||||||||||
|||||||||||||||||||||| ||||||||||||||||||||||||
||||||||||||||||||||||||| ||||||||||||||||||||||||||
|||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||

Computational class

Stroke is in the class of bounded-storage machines.

The minimalistic nature of Stroke has its price: it had to give up Turing completeness.

As every variable (bit) must be represented in code as a sequence of | the program cannot access an infinite number of bits as required for Turing completeness.

Practically, variables of arbitrary size can be used which brings the language very close to being Turing complete according to the structured program theorem, as conditional branching (selection) can easily be simulated via loops.

In short, Stroke can do everything a Turing complete language can but only with limited data.

This weakness is improved in the extension Stroke+-.

External resources