Expressions and Operators
Klyn expressions are compact but strongly typed. This page covers arithmetic, comparisons, boolean logic, identity checks, membership, indexing, interpolation, and operator overloads.
total = 10 + 5
delta = total - 3
scaled = delta * 2
ratio = scaled / 4 # Double: integer / integer is true division
quotient = scaled // 4 # Int: integer division
rest = 17 % 5
power = 2 ** 10
total += 1
total -= 1
total *= 2
total //= 2
total++
total--
The / operator performs true division. Dividing integer primitives therefore
produces a Double, while // performs integer division and keeps the
integer family of the operands. Floating-point division stays in the floating-point family and
supports /=.
assert 9 / 2 == 4.5
assert 9 // 2 == 4
value = 9.0
value /= 2.0
assert value == 4.5
value = 5
assert value == 5
assert value != 6
assert value < 10
assert value <= 5
assert value >= 1
assert 1 < value < 10
Chained comparisons are a built-in language feature and are ideal for range-style conditions.
ready = true
connected = true
failed = false
text = "hello"
assert ready and connected
assert not failed
assert text is String
assert text is not null
assert 10 in [10, 20, 30]
assert "green" not in {"red", "blue"}
Klyn uses and, or, and not. C-style
&& and || are rejected.
name = "Ada"
score = 7
ratio = 3.14159
print(f"Player: {name}")
print(f"Score: {score:03d}")
print(f"Ratio: {ratio:.4f}")
Interpolated strings are often the clearest way to build small textual messages without manual concatenation.
user.name
lines[0]
data[-1]
config["theme"]
result = compute(10)
Strings, fixed arrays, and dynamic array lists support Python-style
[start:stop:step] slices. Bounds may be omitted and negative indexes are resolved
from the end. The stop index is exclusive.
text = "Hello World"
assert text[0:5] == "Hello"
assert text[::-1] == "dlroW olleH"
values = [10, 20, 30, 40, 50]
assert values[1:4] == [20, 30, 40]
assert values[::2] == [10, 30, 50]
values[1:4] = [200, 300, 400]
assert values == [10, 200, 300, 400, 50]
message = "small" if value < 10 else "large"
public operator==(other as Point) as Boolean:
return this.x == other.x and this.y == other.y
c = a @ b
Operators use ordinary syntax at the call site. A type may define only the operators that make sense for its domain.