2 ms·
Also 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 th
by KineticLensman 5y ago
Also 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...