Fundamentals
Implemented — the fundamentals examples are real, checked-in
programs under examples/01-fundamentals/ (15 targets) that round-trip the
language surface on both engines (the Go front end and the self-hosted
kcc engine), producing byte-identical stdout and exit codes. Each file is
gated by pkg/cli/phase114_examples_test.go.
A deeper multi-file round-trip corpus (variables → functions → recursion →
arrays → strings → control flow → structs → maps → types → match → methods →
modules → application layout) also lives under examples/language_foundation/
(13 targets, Phase 102).
File |
Demonstrates |
|---|---|
|
The obligatory first program |
|
|
|
|
|
Functions, returns and composition |
|
|
|
|
|
Concatenation, |
|
Index access, mutation, slices, 2-D arrays, iteration |
|
Map construction/access with string and integer keys, plus |
|
Record types, literals, field reads and mutation |
|
|
|
|
|
|
|
ADT-style tagged |
|
|
Hello world
01_hello_world.kark:
func main() {
println("Hello, Karkain!")
}
Run it:
$ karkain run examples/01-fundamentals/01_hello_world.kark
Expected output:
Hello, Karkain!
A walk through the beginner path:
01_hello_world.kark— print to stdout02_variables.kark+03_constants.kark— bindings and constants04_functions.kark— program structure05_conditionals.kark+06_loops.kark— control flow07_strings.kark+08_arrays.kark— the core collections09_maps.kark+10_structs.kark— associative and record data11_match.kark+12_casts.kark— option matching and numeric casts13_enums.kark+14_adt_match.kark— enums and ADT-style match15_closures.kark— let-bound closures and variable capture
Match (excerpt)
From 11_match.kark — literal-bound arms and Some/None:
func triple(x) {
return match x {
Some(v) => v * 3
None => 0
}
}
Note
For computed values, prefer exhaustive literal arms: wildcard-match behavior is not yet reliable on both engines.
See also
Algorithms — more recursive programs with expected output. Karkain Language Guide — the language guide these examples exercise. First Program — the guided first program.