Foundation Execution model

Getting Started

This page gets you from zero to a runnable Klyn file. It explains how scripts are launched, what a minimal source file looks like, and which rules matter immediately when you move from a one-file experiment to a real module.

Running a Script

The Klyn executable runs a source file directly. The most common workflow is:

klyn hello.kn

Running klyn with no file starts the interactive REPL, which is useful for short experiments and checking type behavior quickly.

klyn
Performance note

Klyn caches compiled object files and reuses them when possible. In normal usage, you run source files directly and let the toolchain decide whether recompilation is needed.

Your First Program

A minimal script can be as small as one statement:

print("Hello, Klyn!")

A more representative example already shows imports, explicit typing, and block syntax:

import klyn.math

attempts as Int = 3

while attempts > 0:
    value = Int(Random.random() * 10)
    print(value)
    attempts--
Executable Scripts and Shebang

Klyn scripts may start with a shebang when you want to execute them directly from a shell:

#!/usr/bin/Klyn

print("Hello from a Klyn script")

This is optional. It is mainly useful for command-line tools and local automation.

A Realistic First Module
import klyn.math

const LIMIT as Int = 5

def describe(value as Int) as String:
    return "small" if value < LIMIT else "large"

public class Counter:
    public property current as Int = 0

    public tick() as Void:
        this.current++

counter = Counter()
while counter.current < LIMIT:
    counter.tick()

print(describe(counter.current))
Part What it shows
import klyn.math The base package klyn is implicit, but subpackages such as klyn.math must be imported.
const LIMIT as Int = 5 Constants are immutable and can be declared with explicit typing.
def describe(...) Top-level functions use def.
public class Counter: Classes use indentation-based blocks, not braces.
this.current++ Properties are accessed with regular dot notation.
Common Beginner Mistakes
Watch for these errors early
  • Writing an import inside a function. Imports are module-level only.
  • Using tabs for indentation. Klyn expects spaces.
  • Assuming type inference means dynamic typing. It does not.
  • Trying to import a type directly instead of importing its package.
Next Step

Continue with Lexical Structure to understand comments, indentation, literals, and source-file rules in detail.