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, plus typed exceptions and resource safety.
File Handling
Text files, folders, CSV, JSON, XML with SAX or DOM, XLSX spreadsheet files, and
archive containers with the klyn.io family of packages.
GUI
Native desktop applications, signals and events, KSS themes, forms, sliders, date input,
dockable workspaces, terminal tabs, embedded HTML content, and custom painting with
Canvas.
Advanced Topics
SQL database access, ORM entity mapping, LLM integration, KAR/KAB distribution, and reflection for larger codebases.
- Start with Getting Started.
- Read Lexical Structure, Packages and Imports, Class Loading, 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.
- After Generics, finish the type model with Exceptions.
- Then learn file work with klyn.io files, CSV, JSON, XML SAX, XML DOM, XLSX, and archives.
- Then open the GUI section with Windows GUI Library, Signals vs Events, GUI Themes and KSS, FormLayout, Slider Widget, DatePicker, DockWorkspace, TerminalWidget, BrowserWidget, and Canvas and Custom Painting.
- Finish the advanced topics with SQL Database Access, ORM and Entities, LLM API and Agents, Reflection, and KAR and KAB Archives.
- Use Code Examples at the end when you want runnable samples that connect several tutorial topics.
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))
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 or qualified type 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 top-level type must live in a file whose name and package path match the type.
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.