[KEP] Add `leave` statement for expressionless return
AuthorOfTheSurf opened this issue · 2 comments
Currently return
statements are required to have an expression, leading to suggestions of returning 0
or null
when there is nothing to return. This is at odds with JavaScript and the notion of returning from a function early.
My proposal is to maintain the current behavior of return
and add a leave
statement that serves as the return-without-a-value. Will parse nicely and leave no doubt in the programmers mind as to what is happening where e.g.:
function double(n):
return
n * 2
end
seems to have undefined behavior where it is unclear if that return
will grab the n * 2
on the next line (it will.)
👍 I think leave
would be a useful statement in this case. In the case above, the return
actually should throw an error though. Since we don't use semicolons, it should look for a return statement in the token on the current line, correct? I could be wrong tho...
Another thing to consider is Javascript functions don't necessarily require a return, unless you want to exit a function early. Which is why leave makes sense!
Thanks for the thumbs, I think that leave
makes a lot of sense semantically. To throw the error, I will add a notion of line
to tokens—so far this is the first use-case for it, but it will be available in the future.