-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functional language which sits between Go & Rust #18
Comments
This would be incredible. In my mind, you're torn between two worlds:
The closest thing in this ballpark I think are Zig are V. Example Zig code: const builtin = @import("builtin");
const std = @import("std");
const fmt = std.fmt;
const io = std.io;
const Op = enum {
Sum,
Mul,
Sub,
};
fn ask_user() !i64 {
var buf: [10]u8 = undefined;
std.debug.warn("A number please: ");
const user_input = try io.readLineSlice(buf[0..]);
return fmt.parseInt(i64, user_input, 10);
}
fn apply_ops(comptime operations: []const Op, num: i64) i64 {
var acc: i64 = 0;
inline for (operations) |op| {
switch (op) {
.Sum => acc +%= num,
.Mul => acc *%= num,
.Sub => acc -%= num,
}
}
return acc;
}
pub fn main() !void {
const user_num = try ask_user();
const ops = [4]Op{.Sum, .Mul, .Sub, .Sub};
const x = apply_ops(ops[0..], user_num);
std.debug.warn("Result: {}\n", x);
} Example V code: struct Point {
x int
y int
}
p := Point{
x: 10
y: 20
}
fn main() {
println(run(5, sqr)) // "25"
// Anonymous functions can be declared inside other functions:
double_fn := fn(n int) int {
return n + n
}
println(run(5, double_fn)) // "10"
// Functions can be passed around without assigning them to variables:
res := run(5, fn(n int) int {
return n + n
})
}
match os {
'darwin' { println('macOS.') }
'linux' { println('Linux.') }
else { println(os) }
}
numbers := [1, 2, 3, 4, 5]
for num in numbers {
println(num)
} Zig is low-level though, with no garbage collection, and is meant as a C-replacement and touts direct interop with C/C++ and can be used a build-replacement. V has both C and JS backends, though is pretty new. Both of them support WASM as a target. |
yeahhh I've seen those! Quite a few seem very close to what I want, maybe I should just accept that the extra 5% is probably not worth the time haha.. |
I think there's definitely room for improvement on both of those, and you're TJ-F*ckin'-Holowaychuk! If you think it would be fun I believe a lot of people would be interested and follow along. Doesn't have to be a production-ready language but it's always neat to see different programming paradigms and experimental languages with new ideas. |
This one is obviously a pretty huge task, but I've always been wanting something inbetween Go & Rust, and have yet to find what I'm looking for. I think with LLVM doing the heavy lifting these days it would be feasible to try it out. It could potentially compile to WASM/JS as well.
The text was updated successfully, but these errors were encountered: