Counting
No jumps and no loops, only a counter that ticks on its own and blocks that wait for it.
A, 2020 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
The user A made Counting in 2020. A program is a list of when blocks, and the run goes through them for ever. Each block whose condition holds runs, and every block that runs adds 1 to the counter cnt. A round in which no block ran adds 1 as well. Nothing can set cnt, so the program steers only by asking what the count is.
Read the story
The only other variable is the accumulator acc, which can be read in and added to but never set.
The machine
| Statement | Does |
|---|---|
when expression | Start a block that runs when the expression holds |
out expression | Print the value and a line feed |
read acc | Read a whole number into acc |
acc += expression | Add to acc |
halt | Stop |
Expressions have whole numbers of any size, strings, cnt, acc and the operators + - * / % ^, == != < <= > >=, && || !. A number and a string join with +, and a string times a number repeats it. A line that starts with % is a comment.
The specification shows the loop in pseudocode. The counter goes up after a block's statements, so a block sees the count from before it ran. One sentence on the specification says the opposite, but then the range from 2 to 100 would print 3 to 101. Precedence is the usual one, with ^ the strongest.
Example
The truth machine reads only while cnt is 0.
The truth machine reads only while cnt is 0. On 0 the second block halts; on 1 the third prints 1 on every round.
The sum of two numbers reads the first into acc and then waits until the counter has climbed to it. Then it reads the second and adds cnt, which equals the first.
Triangular numbers in unary. Each round prints cnt stars until the count passes the input.
The 99 bottles of beer also runs. Its three blocks hold the verses for 3 bottles and up, for 2 and for 1.
Further
See also
Also in Strange time
Write your own in Run Convert a program from Counting
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: counting.
Command line
shib run counting -e 'when 1
out "Hello, World!"
halt'shib manual countingSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/counting.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org