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.
#!/usr/bin/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.
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")
Keep top-level code flush-left. Leading indentation before a top-level statement is rejected, and tabs should not be used as indentation.
| 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 |
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.
Klyn includes keywords for declarations, flow control, typing, and object-oriented features. The ones you will encounter first are:
Continue with Packages and Imports before splitting code across multiple files or packages.
Line comments start with
#. KlynDoc-style documentation comments use the familiar/** ... */form.