-
Notifications
You must be signed in to change notification settings - Fork 0
Intermediate
Real-world usage: streams and forking, classes and objects, the
needassumption system, arrays, file IO, threads, and building real projects.
A signature stream declares what a stream can do; a fork implements it. Calls go through the signature, implementations plug in.
// Signature: what the stream offers
Stream Greeter {
void greet(name string);
}
// Fork: how it works
Greeter FriendlyGreeter {
void greet(name string) {
CIO::println("hello,", name);
}
}
Calling:
Greeter::greet("TAK");
// hello, TAK
A call by signature-stream name falls back to its implementation stream.
Stream Counter {
int count;
void bump();
}
Counter C {
void bump() { this::count = count + 1; }
}
this::count refers to the stream's own field; count resolves through the
scope chain. Bare calls (bump()) work inside the stream.
A class is a stream that can be instantiated:
Class Hero {
int hp;
void __init__() {
this::hp = 100;
}
void takeDamage(d int) {
this::hp = hp - d;
}
}
Main {
void exec() {
Hero h = new Hero(); // __init__ runs
h::takeDamage(30);
CIO::println("hp =", h.hp); // 70
}
}
-
new ClassName()creates an object;__init__is the constructor. -
obj::method(...)calls methods,obj.fieldreads fields. -
Obj::set("name", v)/Obj::get("name")access attributes dynamically. - A washed-away attribute refuses access: "property X was washed away".
need declares a dependency; providers are collected automatically:
need value GREETING; // a constant
need function greet; // a method named greet
need Stream Greeter; // a stream
need Class Hero; // a class
// provider file (any included file):
const string GREETING = "Hello from utils/";
bio build bundles every provider reachable from the main entry
recursively — a need without a provider is an error.
BioLang arrays grow automatically:
int[] squares = new int[4];
for (int i = 0; i < 4; i = i + 1;) { squares[i] = i * i; }
CIO::println(squares); // [ 0 1 4 9 ]
ALL a = new Array(3);
a::set(0, 10);
a::push(40); // grows
CIO::println(a::join("-").res); // join into a string
The Array class and the Vector class are written in BioLang itself;
Arrays::count(), Arrays::forget(v) manage live instances.
void triple(a int) { res a, a * 2, a * 3; } // respond with several values
ALL t = triple(10); // t.res is an array [10, 20, 30]
CIO::println(get t);
res a, b, c; responds with several values at once; they arrive as a raw
array.
FIO is the file stream. Open a file, then read/write through the IO core
methods:
// Writing:
FIO::open("notes.txt", "w");
FIO::println("line one");
FIO::close();
// Reading (text):
FIO::open("notes.txt");
string line = FIO::getln();
CIO::println("read:", line);
FIO::close();
// Reading (bytes):
FIO::open("data.bin");
int byte = FIO::read(); // 0-255, -1 at EOF
Text methods: print / println / get / getln. Byte methods:
write / read. Also FIO::writeFile(path, content) and
FIO::readFile(path) for whole-file operations.
SIO keeps an in-memory string that IO methods read/write against — handy
for building text:
SIO::println("Hello");
SIO::print("World");
CIO::println(SIO::content()); // Hello\nWorld
CIO::println(SIO::buf()); // whole buffer incl. consumed bytes
SIO::clear();
Tools: format, length, upper, lower, trim, contains,
substring, replace.
Calc Worker {
void factorial(n int) {
int r = 1;
for (int i = 2; i <= n; i = i + 1;) r = r * i;
res r;
}
}
Main {
void exec() {
ALL t = Threads::spawn("factorial", 10);
ALL result = Threads::join(t);
CIO::println("10! =", get result); // 3628800
}
}
-
Threads::spawn(name, args...)starts a bare method on a new thread. -
Threads::join(t)waits and fetches its result. -
Threads::active(),Threads::self(),Threads::yield(). - Threads are cooperative — no preemption; a thread must
yieldor finish for others to run.
Round-robin scheduling of tasks:
Taskm::interval(1); // rotate roughly every 1 ms
ALL t1 = Taskm::add("jobA", 5);
Taskm::run(); // run until all tasks finish
CIO::println(get Threads::join(t1));
A project = package.toml + src/ + utils/ + .biolang/deps/:
bio init myapp # skeleton
# edit src/main.bio, add utils/, declare dependencies
bio build myapp -s # standalone executable
bio run myapp # or run interpretedpackage.toml:
name = "myapp"
version = "0.1.0"
[dependencies]
libfoo = { version = "1.0.0", repo = "https://github.com/user/libfoo" }Dependency resolution: the dependency's own repo → BIOLANG_CONFIG file →
~/.biolang/config.toml.
bio shell build hello.bio # → bin/hello (standalone executable)
bio build myapp -s # project → standalone
bio build myapp -m # project → bin/myapp.img (app + platform CLI + libs)
bio build myapp -m dist.zip # → .zip package
bio pack hello.img --entry hello bin/hello
bio run hello.img # run a packageSee Packaging for the .img / .zip formats.
- Home
- Beginner — first steps
- Intermediate — real usage
- Advanced — masterclass
- Build & Run
- Packaging
- Language-Reference
- BR-Model
- BTM-Model