Core syntax Operators

# 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.

Arithmetic and Updates

    total = 10 + 5
    delta = total - 3
    scaled = delta * 2
    ratio = scaled / 4
    rest = 17 % 5
    power = 2 ** 10

    total += 1
    total -= 1
    total *= 2
    total /= 2
    total++
    total--

Comparisons

    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.

Boolean Logic, Identity, Membership

    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"}

Use language keywords

Klyn uses `and`, `or`, and `not`. C-style `&&` and `||` are rejected.

Strings and Interpolation

    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.

Calls, Members, and Indexing

    user.name
    lines[0]
    data[-1]
    config["theme"]
    result = compute(10)

Conditional Expressions

    message = "small" if value < 10 else "large"

Operator Overloading

    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.