Caterpillar

Daily Thought - 2024-08-12

< back to list

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.

<< previous thoughtnext thought >>