Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you discovered that trick yourself, you're very clever. It was documented by Henry Baker and is implemented in Chicken Scheme.

The basic ideas are:

1. All allocations (e.g. consing) take from the stack.

2. Tail calls are stack calls, so we keep consuming stack.

3. No function ever returns; all calls are tail calls. The Lisp code is CPS-transformed. (Since functions in the compiled code don't actually return even when appearing to, the stack-allocated objects remain nicely valid.)

4. When the stack reaches a certain limit, we rewind it. At that point, all the data which we consed on that stack which is still reachable is relocated to the heap, so they remain valid while we clobber the original stack.



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: