Foundation Source format

# Lexical Structure

Klyn source files are intentionally simple to read: indentation defines blocks, comments use `#`, and most punctuation exists only where it improves clarity. This page covers the lexical rules you need before writing larger programs.

A Klyn Source File

    #!/usr/bin/env klyn

    package my.app

    import klyn.math

    const LIMIT = 10

    def compute() as Int:
        return Int(Random.random() * LIMIT)

Not every file needs every part. The shebang is optional, a package declaration is optional, and imports appear only when you need packages outside the default `klyn` package.

Comments

Line comments start with `#`. KlynDoc-style documentation comments use the familiar `/** ... */` form.

    # Single-line comment
    value = 10

    /**
     * Documentation comment for a public API.
     */
    public class Counter:
        pass

Indentation and Blocks

A block starts after a trailing `:`. The following lines must be indented with spaces. Misaligned blocks and tabs are syntax errors.

    if total > 0:
        print("positive")
    else:
        print("zero or negative")

Important

Keep top-level code flush-left. Leading indentation before a top-level statement is rejected, and tabs should not be used as indentation.

Identifiers and Naming

Kind | Typical form | Examples
--- | --- | ---
Types | UpperCamelCase | `Rational`, `TimeZone`, `ArrayList`
Functions and methods | lowerCamelCase | `currentTimeMillis`, `toString`
Variables and properties | lowerCamelCase | `count`, `userName`
Private backing fields | leading underscore | `_value`, `_items`

Basic Literals

    count = 10
    unsignedCount = 10u
    ratio = 0.5
    floatRatio = 0.5f
    initial = 'A'
    name = "Klyn"
    message = """First line
    Second line
    Third line"""

Integer literals default to `Int`. Floating-point literals default to `Double`. Explicit suffixes such as `u` and `f` are useful when you want a more precise literal type at the source level.

Frequently Seen Keywords

Klyn includes keywords for declarations, flow control, typing, and object-oriented features. The ones you will encounter first are:

def class if elif else match case default while for import package return try catch finally throw const pass
Next Step

Continue with Packages and Imports before splitting code across multiple files or packages.