Daily Thought - 2024-08-22
< back to listI've recently started reusing pattern-matching functions for yet another thing: Defining bindings. Let's revisit how those used to work:
a b + => sum .
# code that uses `sum` goes here
This code no longer works, as I removed the binding syntax recently. What it
used to do, is sum up two values and bind the result to the name sum
. This
modified the current scope, which I don't like. Creating a new scope would be
easier on the compiler, and possibly easier on the developer too. Just one less
thing (what exists where in a given scope) to keep track of.
Here's what that could potentially look like:
a b + => sum {
# code that uses `sum` goes here
}
But for now, language simplicity trumps convenience, and we can already do the same thing using an anonymous pattern-matching function:
a b +
{ |sum|
# code that uses `sum` goes here
}
eval
At some point I expect to add back syntax sugar of some kind, to make this more convenient. But under the hood, it can keep re-using pattern-matching functions. This reduces the number of features that the compiler needs to deal with. Only the first compiler passes need to know about syntax sugar. The rest then only need to handle functions.