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.

examples/05-data/

File

Demonstrates

01_word_frequency.kark

Tokenize a text and tally counts in a std.collections map (map_contains_key / map_keys + array_sum)

02_csv_aggregate.kark

CSV-style parse via str_split / str_to_int, then aggregate with array_sum / array_max

03_payload_roundtrip.kark

hex / base64 / UTF-8 byte round-trips through std.encoding

04_token_stats.kark

tokenize text with std.string, then filter, transform and aggregate in one deterministic pass

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.