Hare 是一门新的系统编程语言,它使用静态类型系统、手动内存管理和最小运行时,非常适合编写操作系统、系统工具、编译器以及其他低级高性能任务。
Hare 与 C 最相似,几乎所有用 C 语言编写的程序也可以用 Hare 编写,但 Hare 比 C 更简单。
Hare 的 Hello World
use fmt;
export fn main() void = {
const greetings = [
"Hello, world!",
"¡Hola Mundo!",
"Γειά σου Κόσμε!",
"Привет, мир!",
"こんにちは世界!",
];
for (let i = 0z; i < len(greetings); i += 1) {
fmt::println(greetings[i])!;
};
};
Hare 计算自己的 SHA-256 哈希:
use crypto::sha256;
use encoding::hex;
use fmt;
use hash;
use io;
use os;
export fn main() void = {
const hash = sha256::sha256();
const file = os::open("main.ha")!;
defer io::close(file);
io::copy(&hash, file)!;
let sum: [sha256::SIZE]u8 = [0...];
hash::sum(&hash, sum);
hex::encode(os::stdout, sum)!;
fmt::println()!;
};
评论