The provided example (at least to me) is also convoluted and fails to illustrate the elegance of using a recursive data structure.
In general parlance, an affine transform or rotation matrix would both be more elegant and readable.
The provided example (at least to me) is also convoluted and fails to illustrate the elegance of using a recursive data structure.
In general parlance, an affine transform or rotation matrix would both be more elegant and readable.
This kind of discourse is, IMO, an example of Hacker News at its finest.
(Ultimately you can do "userspace continuations" in any programming language by explicitly transforming your code into CPS, using an explicit FSM if the language doesn't support tail-calls as such, the only price being developer sanity)
I do think there's a real gap in many languages between the natural way to express graph/tree transformations (recursively) and a cache-friendly/mechanical-sympathy-style runtime - see e.g. https://medium.com/@gkossakowski/kentucky-mule-limits-of-sca... . And really this gap shouldn't be there - the language implementation should be able to transform and fuse this kind of tree-walking operation into an efficient implementation - but at the same time it's hard to see how you'd ever make the language spec permit this without resorting to a full-Haskell "everything is lazy everywhere and the language implementation is allowed to evaluate whatever it likes however many times it likes (including 0) in whatever order".