Your First Karkain Project
The First Program page showed a single file. Real projects split
code into a few .kark modules. This page builds the canonical minimal
multi-file project using only stable, supported syntax.
The project shape
Create a directory greeter/ with two sibling files:
greeter/
main.kark # application entry point
math.kark # a sibling module with public exports
main.kark:
import math
func main() {
print(math.twice(21))
}
math.kark:
public func twice(n) {
return n * 2
}
What you are using
import mathimports the siblingmath.karkmodule that lives in the same directory.publicmarkstwiceas an export. A private sibling function is not callable from another module.math.twice(21)is a qualified call against the imported module’s export set.func main()plus the top-levelimportdescribe the program; the pipeline is the same as the single-file case.
Build and run
$ karkain check main.kark
[ok]
$ karkain build main.kark
$ karkain run main.kark
42
Every step uses only stable Karkain 1.2.0 syntax; the same commands work through
both engines (the Go front end and the default self-hosted kcc).
Now add a test
Add math_test.kark next to the others:
import math
func test_twice() {
assert_eq(math.twice(21), 42)
}
Run it:
$ karkain test math_test.kark
1 passed; 0 failed; 0 skipped; 1 total
Layout conventions
For a full project layout (src/, tests/, lib/, karkain init
scaffolding and the manifest) see Project Layout. For importing the
standard library see Modules.
See also
Modules — module imports and the public export model.
Test — writing and running *_test.kark files.
Project Layout — organizing a larger project.
Workspaces — when one repository needs several member packages.