3 ms·
Yes, recursion is tied up with baggage about stack allocation. If recursion is approached as inductive reasoning, those objections never occur. This particular
by silentbicycle 16y ago
Yes, recursion is tied up with baggage about stack allocation. If recursion is approached as inductive reasoning, those objections never occur.
This particularly applies to tail-call optimizations and continuations. If somebody isn't thinking in terms of implementations, continuations are just "you pass in who to return the result to, as an argument." e.g. If it succeeds, tell this function the result, otherwise tell this function the error.
Yet another case of making concepts hard by knowing too much.
- dublinclontarf 16y agoWhy that is the best simple explanation of continuations I have come across yet. Totally right, it's like thinking about how you are able to walk, if you do it trips you up. Dont think about the details just the concepts.
- silentbicycle 16y agoIt's not something people are used to talking explicitly about; it's so ingrained that stuff returns directly to what called it that it never occurs to them. Exceptions are probably the only exception, but I'm not aware of any language besides Common Lisp where an error doesn't unwind the stack - "an exception makes it return several levels up, where the last handler was defined" still fits within a fundamentally stack-based mental model.
- infinite8s 16y agoActually, that description of exceptions requires a stack-based mental model. With true continuations, you have other possibilities for handling the exception (see for example Haskell).
- silentbicycle 16y agoThat's _exactly_ my point. Exceptions (as typically implemented) fit within a stack-based mental model, Common Lisp's resumable exceptions and first-class continuations do not.