First Program
A Karkain program is a .kark file compiled and run through the
karkain CLI.
Hello, World!
Create hello.kark:
println("Hello, Karkain!")
Build and run it:
$ karkain run hello.kark
Hello, Karkain!
That is the complete loop. Every Karkain program starts from here.
What just happened
karkain run hello.karkinvokes the Go front end (orkcc, depending on configuration) to parse the source.The parser produces an AST.
The semantic resolver resolves builtins and scope.
The C emitter produces a
.cfile.GCC or Clang compiles the C to a native executable.
The executable runs and prints
Hello, Karkain!to stdout.
You do not need to understand any of these steps to use Karkain. The CLI handles everything; the pipeline is described in detail in Pipeline Stages.
A second program
Create count.kark:
func count_to(n) {
let i = 1
while(i <= n) {
println(i)
i = i + 1
}
}
count_to(5)
Run it:
$ karkain run count.kark
1
2
3
4
5
Key points:
Functions are declared with
func name(params) { body }.letdeclares a local variable.while(cond) { ... }is the loop form (parentheses required).println(value)prints to stdout.There is no
mainfunction; the top-level scope is the entry point.
What’s next
Build — compile to a native executable.
Run — compile and execute in one step.
Test — write and run tests.
Project Layout — organize a real project.