01 / Records and procedures
Model a score
Define a record, pass it to a procedure, and return the answer.
Score :: struct {
value: s32;
bonus: s32;
}
Total :: (score: Score) -> s32 {
return score.value + score.bonus;
}
Answer :: () -> s32 {
score: Score = Score.{value = 40, bonus = 2};
return Total(score);
}build/bin/ziran check --root . site/examples/hello.zi
build/bin/ziran bundle --root . --entry hello:Answer -o hello.zib site/examples/hello.zi
build/bin/ziran run hello.zib
# 4202 / Standard module
Process text
Import the standard text module with --module-path std. This program returns 1 when a string starts with a prefix after ASCII case folding.
#import "text"
Answer :: () -> s32 {
if StartsWithFoldASCII("Ziran", "zi") {
return 1;
}
return 0;
}build/bin/ziran check --root . --module-path std site/examples/text_demo.zi
build/bin/ziran bundle --root . --module-path std --entry text_demo:Answer -o text_demo.zib site/examples/text_demo.zi
build/bin/ziran run text_demo.zib
# 103 / Native output
Generate native code
The same checked source can generate C, C++, or Go. These commands write source into separate output directories. A C compiler and make build the Ziran tools; Go is needed only if you compile the generated Go output.
build/bin/ziran build --target=c --root . -o out/c site/examples/hello.zi
build/bin/ziran build --target=cpp --root . -o out/cpp site/examples/hello.zi
build/bin/ziran build --target=go --root . -o out/go site/examples/hello.ziNative and portable support can differ by feature. See the current status before choosing a target.