Open johnynek opened 3 months ago
thinking more: the last option above seems the best: if the recursion is tail recursive you must use loop
. you use recur
only when there is non-tail recursion. This allows a reader to clearly see which case we are in.
In scala, there is an annotation
@tailrec
that makes compilation fail if the function is not tail recursive. Tail recursion ensures that the function can be compiled into a loop, and ensures we don't blow the stack.Bosatsu has the optimization, but no way to require that it happens. This seems against the bosatsu way of biasing towards stronger guarantees.
We could have syntax like:
where defloop is just a def where all recursions are in the tail position. Since the tail check can be a kind of a lint, we can do that in parallel with other type checking so that we don't have the sequential error presentation issue.
I don't love the look of
defloop
, but maybe it's the best. Idk. Changing it should be pretty easy since that string can be changed with find and replace. Ideas:hmm... maybe the last one is best... it also makes the tail loop nature local to the function rather than at the top level.