A simple, functional programming language designed for data processing and learning compiler construction
// 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;
K1 embraces functional programming concepts with clean syntax and immutable data structures.
K1 features an efficient bytecode compiler and VM with microsecond-level execution times, delivering solid performance.
Simple syntax and consistent rules make K1 an excellent language for beginners.
Despite its simplicity, K1 includes modern programming features like modules and type inference.
K1's memory management prevents common bugs like buffer overflows and memory leaks.
K1 runs on Windows, macOS, Linux, and embedded platforms with consistent behavior.
To build the K1 compiler, you need CMake (3.10 or higher) and a C++17 compatible compiler.
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
Use the provided build script to compile the K1 compiler.
cd k1
./build.bat
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;
}
Use the K1 compiler to run your program.
k1 run hello.k1
K1 offers solid performance with execution times in the microsecond range for simple programs.
K1's optimized VM executes simple programs efficiently.
Efficient memory management reduces overhead.
Reliable execution across multiple runs.
*Benchmark: Simple "Hello World" program execution time in microseconds (lower is better)
K1's clean syntax makes it easy to write and understand code.
// Hello World in K1 language
import console from "console";
fn main() {
console.log("Hello, World!");
return 0;
}
// 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;
// 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;
// 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;
Learn about K1's syntax and features with our comprehensive documentation.
Get started with K1 today. Download the latest version for your platform.
Build from source for any platform
Connect with other K1 developers and get help with your projects.