compiler
compiler copied to clipboard
🚧 Explicit errors for common pitfalls or mismatched expectations.
Whenever you're learning a new language, unless it's identical to whatever you're familiar with already, it's likely you'll run into a few hiccups along the way when things don't work as you expect.
Ren's design aims to be accessible to JavaScript developers while also taking inspiration from ML and leaning into functional programming a lot more. Inevitably there are going to be things people try to do in Ren that won't work, and while some of those things can be solved at the language level (eg 9281c142c02d0cffbeb4bce2a8c4ed930d3875df), others can be addressed with a friendly error message specific to the situation.
I'd like this issue to act as a tracker for any of these common pitfalls or mismatched expectations, so we can make sure our error messages leave users feeling confident not confused!
- [ ] Potential confusion between
fundeclarations and expressions.
In the programming languages discord, one user pointed out that typically everything that follows the = would be assumed to be an expression. In Ren, this isn't the case:
fun <name> = <...args> =>
<expr>
The arguments list follows the equals, with the body following =>. This was designed to align visually with javascript but there is a semantic difference between the two (x => x + 2 is a valid expression in js, but the equivalent in Ren would be fun x => x + 2)
Because the current expression language doesn't actually include a = operator, we could look for expressions that take the form fun x = y and emit a helpful error showing the expression lambda syntax and explaining the difference.
Example error message:
todo
- [ ] Omitting the
elseclause in anifexpression.
Ren is an expression-oriented language. There are no statements, and that includes if statements. In Ren, an if expression evaluates to a value and so needs an accompanying else clause to evaluate when the condition is false.
Example error message:
todo
- [ ] Attempting to early-return with the
retkeyword.
As mentioned above, Ren does not have statements. A function or let binding body consists of exactly one expression. There is no concept of early returning, and the ret keyword exists purely as a visual marker for that expression.
Example error message:
todo
- [ ] Inserting expressions between local bindings in a function.
Example error message:
todo