Hacker News new | ask | show | jobs
by Retra 2909 days ago
Of course, if your language doesn't support recursion it probably doesn't have first-class functions either. It's pretty trivial to implement recursion if you can pass a function pointer around.
1 comments

I mean, recursion is just a way of saving state on the program's call stack implicitly instead of explicitly in a stack data structure.

fundamentally recursion is syntactical sugar over loops and stacks, as assembly can show you.

C can do recursion. It can't do first class functions, though it can pass function pointers. It just can't create new functions dynamically based on non local variables, at least not without shenanigans.

Recursion is not defined in terms of the execution of the program (such as storing data on the call stack). For example you can have stack less languages with recursion.
> fundamentally recursion is syntactical sugar over loops and stacks, as assembly can show you.

That's one possible implementation of recursion on commodity hardware. Recursion itself is a mathematical method for defining a function which may not even be computable, or may be computable using other primitives.

Functions are syntactic sugar on calls and calls are syntactic sugar on jumps so those dynamic shenanigans would be messing with calling conventions? That might not be too ridiculous.