Daily Thought - 2024-08-12
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.
Okay, so let's get back to conditionals. I implemented if
a while ago, and then found some shortcomings that made me
want to switch to a different solution. This turned out to
be unnecessary, probably, but was an improvement anyway.
So what are the shortcomings of if
? Well, for reasons of simplicity and
elegance, I've implemented it as a built-in function. Basically, if
is just
like any other function. You pass it a conditional value and two closures (one
for the "then" case, one for "else"), and then the built-in if
function
figures out which one of those to call.
But built-in functions are opaque to the compiler. All it knows, is that we created two closures and passed those to a built-in function, with no way to know what it's going to do with them. This leads to multiple problems. I'll explain those later. First, I want to introduce the alternative solution I've implemented, pattern matching in function definitions.
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.