Is the function calling itself via `requestAnimationFrame` still recursive

I’m reading some chenglou’s DOM-related example refactoring, and I’ve just noticed the function calling itself via requestAnimationFrame being declared as rec. Is this a technical necessity or something useful for bug-catching? I mean, technically `requestAnimationFrame shouldn’t result in a stack overflow, and it probably shouldn’t result in queue overflow either, because there’s no more than one callback in the queue at any given moment.

It’s not recursive in the classic sense, but I think the rec is there to tell ReScript “it’s OK; this symbol really has been defined”

1 Like

To say @jdeisenberg s answer in other words:
If you defined a function let draw = ... you can’t reference this function inside of the function’s body. The referenced code needs to pass the defined function as a callback to requestAnimationFrame. To make the function reference available inside of the function itself you need to annotate it like let rec draw = ....
In this specific case rec doesn’t mean the function is called recursively over and over again, but it’s necessary for the function to be able to reference itself inside of it’s body.

Maybe this helps.

2 Likes

Yes, that makes total sense. I’ve quite forgotten that rec concerns references, not runtime behavior. Thanks, @jdeisenberg & @woeps!