A modern, high-performance language designed for building everything from system utilities to web applications.
// Hello World in K2
function main() {
print("Hello, World!");
// Variables
var name = "K2";
var version = 2.0;
print("Welcome to " + name + " " + version);
// Arrays
var languages = ["K2", "Python", "JavaScript"];
for (var i = 0; i < languages.length; i++) {
print("I love " + languages[i]);
}
return 0;
}
K2 is designed for speed with a highly optimized runtime and efficient memory management.
The entire K2 runtime is less than 1MB, making it perfect for embedded systems and microservices.
K2's syntax is designed to be familiar to developers coming from C-like languages while removing unnecessary complexity.
K2's memory management prevents common bugs like buffer overflows and memory leaks.
Easily extend K2 with modules written in K2, C, or any language that supports C ABI.
K2 runs on Windows, macOS, Linux, and embedded platforms with consistent behavior.
K2 is designed for high performance across a wide range of workloads.
Benchmark | K2 | Python | JavaScript | Ruby |
---|---|---|---|---|
Binary Tree | 1.2s | 3.5s | 2.1s | 4.2s |
Regex | 0.4s | 0.9s | 0.6s | 1.3s |
Matrix Mult. | 0.7s | 2.2s | 1.5s | 2.8s |
File I/O | 0.3s | 0.8s | 0.7s | 1.1s |
K2's clean syntax makes it easy to write and understand code.
// Hello World in K2
function main() {
print("Hello, World!");
return 0;
}
// Fibonacci sequence in K2
function fibonacci(n) {
if (n <= 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
function main() {
for (var i = 0; i < 10; i++) {
print("Fibonacci(" + i + ") = " + fibonacci(i));
}
return 0;
}
// Simple web server in K2
import http
function handleRequest(request, response) {
response.setHeader("Content-Type", "text/html");
response.write("<html><body>");
response.write("<h1>Hello from K2!</h1>");
response.write("<p>You requested: " + request.url + "</p>");
response.write("</body></html>");
response.end();
}
function main() {
var server = http.createServer(handleRequest);
server.listen(8080);
print("Server running at http://localhost:8080/");
return 0;
}
// Simple GUI application in K2
import gui
function main() {
var window = gui.createWindow("K2 GUI Example", 400, 300);
var button = gui.createButton("Click Me!", 150, 120, 100, 30);
button.onClick(function() {
gui.showMessage("Hello!", "You clicked the button!");
});
window.add(button);
window.show();
gui.runMainLoop();
return 0;
}
Experience the next generation of K2 programming with our new Nahir UI framework.
Nahir UI components render in microseconds, providing instant visual feedback and smooth animations.
Build complex interfaces with reusable, composable components that maintain K2's performance benefits.
Utilizes the new K2 ramdisk cache system for ultra-fast component state management and rendering.
Automatically adapts to any screen size with zero performance penalty, perfect for mobile applications.
// Nahir UI Example
import nahir
function main() {
// Create a new Nahir application
var app = nahir.createApp("My Nahir App");
// Define the app state
var state = {
counter: 0,
theme: "light"
};
// Create a component
var counterComponent = nahir.component("counter", function(props) {
return nahir.div({ class: "counter-container" }, [
nahir.h2({}, "Counter: " + props.value),
nahir.button({
onClick: function() { props.onIncrement(); }
}, "Increment"),
nahir.button({
onClick: function() { props.onReset(); }
}, "Reset")
]);
});
// Render the application
app.render(function() {
return nahir.div({ class: "app" }, [
nahir.h1({}, "Nahir UI Example"),
counterComponent({
value: state.counter,
onIncrement: function() { state.counter++; },
onReset: function() { state.counter = 0; }
}),
nahir.button({
onClick: function() {
state.theme = state.theme === "light" ? "dark" : "light";
document.body.className = state.theme;
}
}, "Toggle Theme")
]);
});
// Start the application
app.mount("#app");
}