Skip to main content
Klar

Klar Programming Language

No ambiguity. No surprises. The code explains itself.

Klar is an AI-native application programming language designed for AI code generation. Every construct is self-describing, parseable at a glance, and has defined semantics.

Quick Start

fn main() -> i32 {
    let message: string = "Hello, Klar!"
    println(message)
    return 0
}

Save as hello.kl and run:

klar run hello.kl

Documentation

Philosophy

Getting Started

Language Guide

Type System

Memory Management

Guides

Advanced Topics

  • Operators - Complete operator reference
  • Comptime - Compile-time programming
  • Builtin Traits - Eq, Ordered, Clone, Drop, etc.
  • FFI - Foreign Function Interface for C interop

Design

Appendix

Design Philosophy

Parseable at a Glance

Every construct is self-describing without surrounding context:

[i32; 3]       // Array type - self-contained, no lookahead needed
and, or, not   // Keywords over cryptic symbols
let x: i32 = 5 // Explicit type annotations

No Undefined Behavior

Every operation has defined semantics:

let a: i32 = 100
let b: i32 = a +% 200  // Wrapping addition (explicit overflow handling)
let c: i32 = a +| 200  // Saturating addition (clamps at max)

No Implicit Conversions

Type changes are always explicit:

let x: i64 = 42.as#[i64]     // Safe conversion
let y: ?i32 = "42".to#[i32]  // Fallible conversion
let z: i8 = x.trunc#[i8]     // Truncating conversion

Ownership Without Complexity

Memory safety through ownership, but simpler than Rust:

let data: Rc#[Data] = Rc.new(Data { ... })  // Reference counted
let copy: Rc#[Data] = data.clone()          // Explicit clone

C Interoperability (FFI)

Call C functions and use C types with explicit unsafe blocks:

extern { fn puts(s: CStr) -> i32 }

fn main() -> i32 {
    unsafe { puts("Hello from Klar FFI!".as_cstr()) }
    return 0
}

Version

Current version: 0.4.0

License

See LICENSE for details.