Variables & Constants
In Kyna, you give names to values using two declarations: var for values that can change, and const for values that stay fixed.
Declaring Mutable Variables with var
Use var when you plan to reassign the value over time:
var count = 1; # Type inferred as 'int'
print("Count:", count); # 1
count = count + 1; # Reassignment
print("Count:", count); # 2
You can optionally write explicit nominal type annotations:
var username: str = "Alice";
var score: int = 100;
var isActive: bool = true;
Declaring Immutable Constants with const
Use const for values that should never be reassigned after initialization. The compiler statically enforces immutability at build time:
const maxRetries: int = 3;
const serverEndpoint = "https://api.kyna.dev";
# Attempting reassignment causes a compile-time error:
# maxRetries = 5; # Error: cannot assign to const 'maxRetries'
Naming Conventions & Identifiers
- Identifiers must start with a letter (
a-z,A-Z) or an underscore_. - Subsequent characters may include letters, digits (
0-9), and underscores. - Identifiers are case-sensitive:
servicePortandServicePortare distinct bindings.
var total_requests = 10;
var maxBufferCapacity = 1024;
var _internalState = "READY";
Type Inference Rules
When you omit a type annotation, Kyna infers the tightest nominal type from the right-hand expression:
var a = 42; # inferred as int
var b = 3.14; # inferred as float
var c = "hello"; # inferred as str
var d = true; # inferred as bool
var e = [1, 2, 3]; # inferred as int list