4 ms·
> Oh, also, functions cannot be recursive (without passing in a function to itself), because we won't have the function bound to a name in the local context whe
by tshaddox 3y ago
> Oh, also, functions cannot be recursive (without passing in a function to itself), because we won't have the function bound to a name in the local context when defining itself. Fun, right?
The startup accelerator that runs this forum is named after a pretty neat thing you can do with a language that only has anonymous functions:
https://en.wikipedia.org/wiki/Fixed-point_combinator https://en.wikipedia.org/wiki/Fixed-point_combinator
- Joker_vD 3y agoYou don't even need that, there is a much more efficient way in a language that supports let-bindings (but not letrec): let f' = func(f, g, other_args...) { // ... g(f, g, whatever...); // ... }; let g' = func(f, g, other_args...) { // ... f(f, g, whatever...); // ... } let f = func(other_args...) { return f'(f', g', other_args...); } let g = func(other_args...) { return g'(f', g', other_args...); } That's basically just closure conversion, only instead of doing it the compiler backend, you do it manually yourself.
- tshaddox 3y agoThat’s true, although I wasn’t sure if simpler approaches using let bindings like that would fall under the author’s “without passing in a function to itself.”
- Joker_vD 3y agoI understood that passage as "our let won't be letrec, so no recursion for you (unless you do some self-passing trick, of course)".