DoFor

From Esolang
Jump to navigation Jump to search

DoFor

DoFor is an esoteric programing language.

It is special because it uses the same command for input, output and variables.

se also: https://esolangs.org/wiki/BullScript

Commands:

Commands
Command Use
DO Action Type Value_FOR Variable; does Action using Value (that has the type Type) to variable
IF(C){CODE}; does CODE if C is true
LABEL X; sets the label X
GOTO X; goes to the label X

Actions:

a command for reference: DO [Action] [Type] [Value]_FOR [Variable]

(Just to clarify, the square brackets are not supposed to be around the variable names and values in your code, it's just so you don't get confused when reading my instructions)

SET      sets [Variable] to [Value]
ADD      adds [Value] to [Variable]
IMPORT   imports the variable with the name [Value] from the BullScript file with the name [Variable]

Types:

a command for reference: DO [Action] [Type] [Value]_FOR [Variable]

INT      sets/adds [Value] to [Variable] as an integer
STR      sets/adds [Value] to [Variable] as a string
VAR      sets/adds the variable with the name [Value] to [Variable]
CON      sets [Variable] to the boolean value of [Value] (there is DO SET CON VAR1=VAR2_FOR C; and DO SET CON VAR1<VAR2_FOR C;)

Outputing:

To give output you save your data to the variable OUTPUT. when there is data in the variable OUTPUT it will be printed and the OUTPUT variable will become empty again

Inputing:

to get input you do it like this:

DO Action Type INPUT_FOR Variable;

the input will be taken as the type you put in the place of Type.


Example programs:

cat program

LABEL LOOP;
DO SET STR INPUT_FOR OUTPUT;
GOTO LOOP;

a cat program takes input and prints it out again

truth machine:

DO SET INT INPUT_FOR IN;
DO SET INT 1_FOR Check;
DO SET CON IN=Check_FOR C;
IF(C){
LABEL LOOP;
DO SET INT 1_FOR OUTPUT;
GOTO LOOP;
};
DO SET INT 0_FOR OUTPUT;

a truth machine checks if the input is a 1 and if it is it outputs ones forever and if it's 0 it outputs a single 0



functions:

creating a function:

DO SET INT 1_FOR DONE;
DO SET INT 2_FOR CHECK;
DO SET CON DONE<DONE_FOR C;
LABEL FunctionName;
IF(C){

your code here

DO SET CON DONE<DONE_FOR C;
DO ADD INT 1_FOR DONE;
GOTO CALL;
};

all you need to do is replace "your code here" with the code that you want in the function and FunctionName with the name you want your function to have.

using a librairy:

in the libExample.BS file:

¤h65#
¤hello10#

in the DoForExample.txt file:

DO IMPORT VAR h_FOR libExample.BS;
DO SET VAR h_FOR OUTPUT;

the output:

11

calling a function:

LABEL CALL;
DO SET CON DONE<CHECK_FOR A;
IF(A){
DO SET CON DONE=DONE_FOR C;
GOTO FunctionName;
};
DO SET INT 1_FOR DONE;

all you need to do here is replace FunctionName with the name of the function you want to call. if your function uses any variables then you should probably define them in the IF(A) code block


interpreter download:

https://github.com/TinyGuy32/DoFor