Crosscut

Daily Thought - 2024-09-07

Hey, I'm Hanno! These are my daily thoughts on Crosscut, the programming language I'm creating. If you have any questions, comments, or feedback, please get in touch!

This thought was published before Crosscut was called Crosscut! If it refers to "Caterpillar", that is the old name, just so you know.

< back to list

The comptime feature in Zig is pretty interesting! It allows you to do some neat things. Here's an example from Zig's documentation:

fn max(comptime T: type, a: T, b: T) T {
    return if (a > b) a else b;
}

It's a generic max function that works with any type that provides an > operator. It's pretty similar to how generics work in Rust, but the type parameter is more similar to a normal function parameter. There are more interesting things you can do with comptime in Zig, but I wanted to show you this example, as it gave me an idea.

I'm wondering, can Caterpillar go a step further and make type parameters even less of a special thing? Like, make them completely normal function parameters, no special syntax or keyword required? And on top of that, maybe create a more natural separation between compile-time and runtime parameters?

I think the answers to all those questions might be "yes". I have an idea, and I'd like to tell you about it tomorrow.

<< previous thoughtnext thought >>

Hey, you! Want to subscribe to my daily thoughts? Just let me know (maybe include a nice message, if you're up for it), and I'll send you an email whenever I post a new one.