Crates.io | krab |
lib.rs | krab |
version | 0.1.3 |
source | src |
created_at | 2023-04-11 16:39:07.602113 |
updated_at | 2023-04-13 20:28:45.845836 |
description | Krab is a simple and minimalistic interpreted programming language written in Rust. |
homepage | |
repository | https://github.com/tAtomDev/krab |
max_upload_size | |
id | 836172 |
size | 104,863 |
Krab is a simple and minimalistic interpreted programming language written in Rust. It has almost no functionality and it is not meant to be used for any serious purpose. It was created as a fun experiment to see how compact and simple a programming language can be.
Krab has a very simple syntax that resembles Rust. Here are some examples:
// Declare a variable with explicit type
let x: int = 42;
// Declare a variable with implicit type
let y = 3.14;
// Declare a constant
const z = true;
// Define a function
fn add(a: int, b: int) -> int {
// Return without semicolon
a + b
}
// Call a function
let result = add(x, 8);
// Print to stdout
print(result);
// Use if as an expression
let max = if x > y {
x // No semicolon here!
} else {
y // Or here!
};
// Use while loop for iteration
let i = 0;
while i < 10 {
print(i);
i = i + 1;
}
To use Krab, you need to install Rust and run cargo run
in the project directory.
This will launch a REPL where you can write Krab code interactively. You can also execute a .krab file by passing its path to the REPL. For example:
$ cargo run
- Krab 0.1 REPL
Type 'exit' to leave or 'clear' to clear the terminal
> ./code.krab
Hello from Krab!
> 5 + 5
10
>
There is no good reason to use Krab over any other programming language. It is just a toy language that was made for fun and learning. If you are looking for an embedded scripting language for your Rust code, you should check out rhai instead.
However, Krab is better than JavaScript! (but slower)