3 ms·
Is there anything I can read in order to discover the general principle in creating a tail-recursion optimizer? I know how to ensure it's triggered, but not nec
by pmarreck 5y ago
Is there anything I can read in order to discover the general principle in creating a tail-recursion optimizer? I know how to ensure it's triggered, but not necessarily how to write one...
- stopachka 5y agoSICP has a great chapter on it: https://sarabander.github.io/sicp/html/5_002e4.xhtml#g_t5_002e4_002e2 https://sarabander.github.io/sicp/html/5_002e4.xhtml#g_t5_00...
- KineticLensman 5y agoAlso see Make a Lisp - a build a lisp project that has a specific section on tail recursion [0]. When I went through the MAL process, TCO was actually one of the more straight forward sections (compared with say macros). The basic idea is quite simple - take your eval function and wrap it's body in a loop. For several of the special forms, instead of recursing into eval, rebind eval's arguments and go back round the loop. Forms where something is done after the call to eval still have to recurse, but they are actually in the minority. [0] https://github.com/kanaka/mal/blob/master/process/guide.md#step-5-tail-call-optimization https://github.com/kanaka/mal/blob/master/process/guide.md#s...