Crosscut

Daily Thought - 2024-08-08

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

A few weeks ago, I implemented if, to replace the previous conditional primitives. In the time since, I've discovered shortcomings of if, and have reconsidered my approach to conditionals. I'd like to explain what those shortcomings are, and what other solution I've come up with. But before I can get to that, I need to start with some basics.

So, purely functional languages. If you can't mutate local variables, then there's really no sensible way to have the typical looping constructs from imperative languages. You need recursion. But if you implement recursion naively, then an endless loop will endlessly grow your stack memory use. That won't do.

The solution to that is tail call elimination, and it's quite straight-forward: If a call is the last expression in its scope, then you don't need to create a new stack frame. You don't need to return to the current scope anyway, so you can reuse the already existing stack frame instead. Tomorrow, I want to expand on that, and explain what that has to do with conditionals.

<< 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.