Skip to content

Beginner

Enoch-199811 edited this page Aug 9, 2026 · 3 revisions

Beginner — First steps with BioLang

English | 中文 | Русский

This page teaches the core concepts and control flow. You need nothing but a built bio binary and a text editor.

What is BioLang?

BioLang is a stream-oriented language. Instead of "everything is an object", here everything is a stream — a flow of requests and responses. Every operation you perform is a request that may be refused. This makes error handling a first-class part of the language, not an afterthought.

Running your first program

Build the interpreter:

make
# → bin/bio

Create hello.bio:

program main;

Main {
    void exec() {
        CIO::println("Hello, BioLang!");
    }
}

Run it:

bin/bio hello.bio
# Hello, BioLang!

Every program has the same skeleton:

  • program main; — declares this file is a main program (it has an entry).
  • Main { ... } — the main program stream.
  • void exec() { ... } — the method that runs when the program starts.

Base types and variables

Five base types:

Type Meaning Example
int integer 42, -7
float single-precision number 3.14
double double-precision number 3.14159265358979
string text "hello"
char single character 'x'

Declaring variables:

int age = 30;
string name = "BioLang";
double pi = 3.14159;
char grade = 'A';

A const is a read-only program-level constant:

const int SPEED = 9;

The request model: res, ref, get, cause

Every call returns a request result that is either a success (res) or a refusal (ref). This is the heart of BioLang.

ALL result = add(3, 4);     // a request result

Use get to unwrap a success, cause to get the refusal reason:

CIO::println(get add(3, 4));        // 7
CIO::println(cause div(1, 0));      // refused: division by zero
  • get x — the value of a successful request.
  • cause x — the reason a request was refused.
  • ALL x = ... — captures both; .res and .cause also work.

Operators

Arithmetic: + - * / %

int a = 7 + 3;      // 10
int b = a * 2;      // 20
int c = b / 7;      // 2  (integer division)
int d = b % 7;      // 6  (remainder)

Increment and decrement: i++, i--, plus compound forms.

Control flow

if / else if / else

if (score >= 90) {
    CIO::println("A");
} else if (score >= 60) {
    CIO::println("B");
} else {
    CIO::println("C");
}

while

int i = 0;
while (i < 5) {
    CIO::println("i =", i);
    i = i + 1;
}

for

for (int i = 0; i < 5; i = i + 1;) {
    CIO::println("square", i, "=", i * i);
}

Note the ; after the update expression — the three clauses are separated by semicolons and the whole header ends with ;.

break and continue

for (int i = 0; i < 10; i = i + 1;) {
    if (i == 3) continue;    // skip 3
    if (i == 7) break;       // stop at 7
    CIO::println(i);
}

Console input and output

CIO::print("Enter your name: ");     // no newline
string name = CIO::getln();          // read a line of text
CIO::println("Hello,", name);        // prints: Hello, <name>

CIO is the console stream: print, println, get, getln, readInt, readNumber.

Putting it together

A small guessing game (uses everything above):

program main;

Main {
    void exec() {
        const int SECRET = 7;
        CIO::println("Guess the number (1-10)!");

        for (int tries = 0; tries < 3; tries = tries + 1;) {
            int guess = CIO::readInt();
            if (guess == SECRET) {
                CIO::println("Correct! You win.");
                res;                  // success, end the program
            } else if (guess < SECRET) {
                CIO::println("Too low.");
            } else {
                CIO::println("Too high.");
            }
        }
        CIO::println("Out of tries. The answer was", SECRET);
    }
}

What's next

  • Intermediate — streams, classes, files, projects, threads.
  • Advanced — smart references, binary libraries, packaging, cross-platform builds.
  • Examples in the repo — 15 runnable, heavily commented programs.

Clone this wiki locally