Loading K1...

K1 Programming Language

A simple, functional programming language designed for data processing and learning compiler construction

hello.k1
// Hello World in K1 language

// Import the standard library
import console from "console";

// Define the main function
fn main() {
    // Print a greeting
    console.log("Hello, World from K1!");
    
    // Calculate and print the result
    let result = calculate(5, 7);
    console.log("5 + 7 =", result);
    
    return 0;
}

// Define a calculation function
fn calculate(a, b) {
    let sum = a + b;
    return sum;
}

// Export the calculate function
export calculate;

Key Features

Functional Paradigm

K1 embraces functional programming concepts with clean syntax and immutable data structures.

Optimized VM

K1 features an efficient bytecode compiler and VM with microsecond-level execution times, delivering solid performance.

Easy to Learn

Simple syntax and consistent rules make K1 an excellent language for beginners.

Modern Features

Despite its simplicity, K1 includes modern programming features like modules and type inference.

Memory Safe

K1's memory management prevents common bugs like buffer overflows and memory leaks.

Cross-Platform

K1 runs on Windows, macOS, Linux, and embedded platforms with consistent behavior.

Getting Started

To build the K1 compiler, you need CMake (3.10 or higher) and a C++17 compatible compiler.

1

Download K1

Get the latest version of K1 from our GitHub repository or use the download button above.

git clone https://github.com/k-lang/k1.git
2

Build the Compiler

Use the provided build script to compile the K1 compiler.

cd k1
./build.bat
3

Write Your First Program

Create a new file with a .k1 extension and write your first K1 program.

// hello.k1
import console from "console";

fn main() {
    console.log("Hello, World!");
    return 0;
}
4

Run Your Program

Use the K1 compiler to run your program.

k1 run hello.k1

Efficient Performance

K1 offers solid performance with execution times in the microsecond range for simple programs.

~150 μs
Execution Time

K1's optimized VM executes simple programs efficiently.

Minimal
Memory Allocations

Efficient memory management reduces overhead.

Consistent
Performance

Reliable execution across multiple runs.

K1 vs Other Languages

C++
50μs
Rust
75μs
K1
150μs
Go
200μs
Java
300μs
Python
500μs

*Benchmark: Simple "Hello World" program execution time in microseconds (lower is better)

Code Examples

K1's clean syntax makes it easy to write and understand code.

hello.k1
// Hello World in K1 language
import console from "console";

fn main() {
    console.log("Hello, World!");
    return 0;
}
fibonacci.k1
// Fibonacci sequence in K1
import console from "console";

fn fibonacci(n) {
    if (n <= 1) {
        return n;
    }
    return fibonacci(n - 1) + fibonacci(n - 2);
}

fn main() {
    for (let i = 0; i < 10; i++) {
        console.log("Fibonacci(" + i + ") = " + fibonacci(i));
    }
    return 0;
}

export fibonacci;
webserver.k1
// Simple web server in K1
import http from "http";
import console from "console";

fn handleRequest(request, response) {
    response.setHeader("Content-Type", "text/html");
    response.write("<html><body>");
    response.write("<h1>Hello from K1!</h1>");
    response.write("<p>You requested: " + request.url + "</p>");
    response.write("</body></html>");
    response.end();
}

fn main() {
    let server = http.createServer(handleRequest);
    server.listen(8080);
    console.log("Server running at http://localhost:8080/");
    return 0;
}

export handleRequest;
dataproc.k1
// Data processing in K1
import fs from "fs";
import console from "console";

fn processData(data) {
    let lines = data.split("\n");
    let result = [];
    
    for (let i = 0; i < lines.length; i++) {
        let line = lines[i].trim();
        if (line.length > 0) {
            let parts = line.split(",");
            let sum = 0;
            
            for (let j = 0; j < parts.length; j++) {
                sum += parseInt(parts[j]);
            }
            
            result.push(sum);
        }
    }
    
    return result;
}

fn main() {
    let data = fs.readFile("data.csv");
    let results = processData(data);
    
    console.log("Processing results:");
    for (let i = 0; i < results.length; i++) {
        console.log("Row " + i + " sum: " + results[i]);
    }
    
    return 0;
}

export processData;

Language Documentation

Learn about K1's syntax and features with our comprehensive documentation.

Full Documentation API Reference

Download K1

Get started with K1 today. Download the latest version for your platform.

Windows

Windows 10/11 (64-bit)

Download for Windows

macOS

macOS 10.15+ (Intel/Apple Silicon)

Download for macOS

Linux

Ubuntu, Debian, Fedora, CentOS

Download for Linux

Source Code

Build from source for any platform

Join the Community

Connect with other K1 developers and get help with your projects.