Caterpillar

Daily Thought - 2024-06-30

< back to list

I've mentioned before that Caterpillar could become less restrictive around how functions are defined, as it grows more features that help to notice and prevent mistakes. Then, function arguments could become implicit, which could look like this:

fn increment { 1 + }

We know that + takes two arguments, and since we only provide one argument, we know that the function needs to take another one. But maybe we want to make that explicit, in some cases. If we combine the previous syntax with my idea for assignment expressions, that could look like this:

fn increment { => x
    { x 1 + }
}

On a conceptual level, I find this elegant. There is no special syntax for optional function arguments. Every function declaration would just be fn <name> <body>, and you can combine that with an orthogonal feature, binding expressions, to specify arguments where that is desirable.

But the syntax is kind of ugly, with the double parentheses. Maybe I can come up with something better.

<< previous thoughtnext thought >>