esolang

DoFor

One statement does everything, and printing is just setting a variable.

Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: 0

The idea

DoFor uses the same command for variables, input and output. DO SET INT 5_FOR X; sets X to 5. Setting the variable OUTPUT prints it and empties it again, and the value INPUT reads a line instead of naming one. Next to DO there are only IF blocks, labels and GOTO.

Read the story

Functions are built from these. A function is an IF block guarded by a boolean, and a call sets the boolean and jumps in. The function jumps back to a label at the call when it is done.

The machine

StatementDoes
DO SET Type Value_FOR Var;Set Var to Value
DO ADD Type Value_FOR Var;Add Value to Var
IF(C){ ... };Run the block if C is true
LABEL X; GOTO X;Mark a place; jump there
TypeValue is
INTA whole number
STRText
VARThe name of a variable whose value it takes
CONA=B or A<B on two variables, giving a boolean

Each print ends with a line feed. The specification also has DO IMPORT, which takes a variable from a BullScript file. This implementation has no files and leaves it out.

Example

The truth machine.

The truth machine. On 0 the IF block is skipped and the last line prints a single 0. On 1 the block loops on GOTO LOOP and prints 1 forever.

The cat reads a line straight into OUTPUT, which prints it. The end of the input ends the loop.

Expected: hello

Further

Also in Turing tarpits

Write your own in Run Convert a program from DoFor

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: dofor.

Command line

shib run dofor -e 'LABEL LOOP;
DO SET STR INPUT_FOR OUTPUT;
GOTO LOOP;' --input 'hello
world
'
shib manual dofor

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/dofor.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org