Official tutorial Language syntax Static typing

Klyn Tutorial

This tutorial is meant to teach Klyn as a language, not just to list keywords. It starts with source-file rules and builds progressively toward classes, generics, exceptions, and reflection. Use it as the main path when you want to become productive in Klyn.

What This Tutorial Covers

Foundations

Running scripts, understanding file structure, indentation, comments, packages, imports, and Klyn coding conventions.

Core Syntax

Typing, expressions, operators, control flow, functions, collection literals, and iteration.

Types and OOP

Classes, constructors, properties, inheritance, interfaces, enums, annotations, and generics.

Advanced Topics

Exceptions, resource management, and reflection for larger and more introspective codebases.

Recommended Reading Order
  1. Start with Getting Started.
  2. Read Lexical Structure, Packages and Imports, and Coding Conventions before writing multi-file code.
  3. Learn the typing model in Typing and Constants before relying on inference everywhere.
  4. Move through Expressions, Statements, and Functions.
  5. Once the procedural part is clear, continue with Classes, Properties, and Inheritance.
  6. Finish with Generics, Exceptions, and Reflection.
What Klyn Feels Like
Readable surface syntax
import klyn.math

const LIMIT as Int = 3

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

value = Int(Random.random() * 10)
print(classify(value))
Structured object model
public class Counter:
    public property current as Int = 0

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

counter = Counter()
counter.tick()
print(counter.current)
Non-Negotiable Language Rules
Read this before writing real code
  • Klyn is always typed. Inference helps you write less, but values do not become dynamically typed later.
  • Only the package klyn is imported automatically. Any other package must be imported explicitly.
  • Imports belong at module level. Do not import from inside a function or a class.
  • Blocks start after : and use spaces. Tabs are rejected.
  • A public class must live in a file whose name and package path match the class.
Next Step

Continue with Getting Started if you want your first runnable Klyn program, or jump to Typing and Constants if you already know the execution model and want the language rules first.