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.
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.
- Start with Getting Started.
- Read Lexical Structure, Packages and Imports, and Coding Conventions before writing multi-file code.
- Learn the typing model in Typing and Constants before relying on inference everywhere.
- Move through Expressions, Statements, and Functions.
- Once the procedural part is clear, continue with Classes, Properties, and Inheritance.
- Finish with Generics, Exceptions, and Reflection.
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))
public class Counter:
public property current as Int = 0
public tick() as Void:
this.current++
counter = Counter()
counter.tick()
print(counter.current)
- Klyn is always typed. Inference helps you write less, but values do not become dynamically typed later.
- Only the package
klynis 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.
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.