Data
Implemented — a compact data-handling corpus lives under
examples/05-data/: word frequency, CSV-style aggregation, binary/text
payload round-trips and a text token-statistics pipeline. Every file here
runs byte-identically on both engines (Go front end and the self-hosted
kcc engine) and is gated by pkg/cli/phase114_examples_test.go.
Data-storage (databases) is now implemented as a separate category: Database.
File |
Demonstrates |
|---|---|
|
Tokenize a text and tally counts in a |
|
CSV-style parse via |
|
hex / base64 / UTF-8 byte round-trips through |
|
tokenize text with |
Token statistics
examples/05-data/04_token_stats.kark — a small text-processing pipeline
(token count, long-word filter, per-word character totals):
// Status: Runnable
// Engine: both (Go front end + self-hosted kcc)
// Category: 05 Data
//
// A text-processing pipeline: tokenize a fixed sentence, then filter
// (count long words), transform (per-word character totals) and aggregate
// (grand totals) in a single deterministic pass over std.string tokens.
//
// Run: karkain run examples/05-data/04_token_stats.kark
import std.string
func main() {
let text = "the quick brown fox jumps over the lazy dog"
let words = str_split(text, " ")
print(len(words)) // token count
let long_words = 0
let total_chars = 0
let i = 0
while (i < len(words)) {
total_chars = total_chars + len(words[i])
if (len(words[i]) >= 5) {
long_words = long_words + 1
}
i = i + 1
}
print(long_words) // words with 5+ letters
print(total_chars) // characters excluding spaces
}
Expected output (verified on both engines):
9
3
35
Word frequency
Excerpt from examples/05-data/01_word_frequency.kark:
func main() {
let words = ["karkain", "data", "karkain", "data", "hello"]
...
}
Run any of them directly:
$ karkain run examples/05-data/01_word_frequency.kark
See also
std.collections — Array and map helpers and std.encoding — Hex, Base64 and UTF-8 codecs — the stdlib modules these examples exercise. Database — the not-yet-implemented storage category.