-
Notifications
You must be signed in to change notification settings - Fork 0
Beginner
English | 中文 | Русский | Español | Português | 繁體中文 | Deutsch
This page teaches the core concepts and control flow. You need nothing but a built
biobinary and a text editor.
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.
Build the interpreter:
make
# → bin/bioCreate 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.
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;
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;.resand.causealso work.
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.
if (score >= 90) {
CIO::println("A");
} else if (score >= 60) {
CIO::println("B");
} else {
CIO::println("C");
}
int i = 0;
while (i < 5) {
CIO::println("i =", i);
i = i + 1;
}
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 ;.
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);
}
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.
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);
}
}
- Intermediate — streams, classes, files, projects, threads.
- Advanced — smart references, binary libraries, packaging, cross-platform builds.
- Examples in the repo — 15 runnable, heavily commented programs.
- Home
- Beginner — first steps
- Intermediate — real usage
- Advanced — masterclass
- Build & Run
- Packaging
- Language-Reference
- BR-Model
- BTM-Model