Lesson 17

Modules with go

Using 'go' blocks for named entry points / modules

← All lessons   Prev   Next →

// Tutorial 17: Modules with go
// Using 'go' blocks for named entry points / modules

// 'go' defines a named block, like a module or named main
go math_demo {
    func square(n) { emit n * n }
    func cube(n) { emit n * n * n }

    kp("=== Math Demo ===")
    let i = 1
    while i <= 5 {
        kp("" + i + ": square=" + square(i) + " cube=" + cube(i))
        i = i + 1
    }
}
Click ▶ Run to execute. Lessons using k:fs/k:http/match/struct need the real runtime.

Tip: this code box is editable — tweak it, then hit Run, or copy into a .k file and run locally.

Run it locally: kcc -r tutorial/17_go_blocks.k

← All lessons   Prev   Next →