Plurrrr

Fri 08 Jan 2021

Scipy Lecture Notes

Tutorials on the scientific Python ecosystem: a quick introduction to central tools and techniques. The different chapters each correspond to a 1 to 2 hours course with increasing level of expertise, from beginner to expert.

Source: Scipy Lecture Notes.

How Tail Call Optimization Works

Most undergraduate computer sciences courses teach students about tail call optimization (TCO), and even if you don't have a formal computer science background the concept is talked about enough that you might be familiar with it anyway, especially if you've ever done any functional programming. However, I think the way TCO is normally taught is very confusing, because it's normally taught in the context of recursion. It's taught this way because without TCO many recursive functions can blow up the stack causing a stack overflow. Therefore by teaching people about TCO in the context of recursion, you can teach them why optimizing compilers (or interpreters) can run tail recursive code efficiently and without causing a stack overflow.

However, the recursion case for TCO is actually not the norm: in fact, if you're writing code in C, C++, or any most other languages with an optimizing compiler you're almost certainly having TCO applied all over your programs even if they don't use any recursion whatsoever. Understanding the non-recursive case of TCO is actually a lot simpler, and if you understand the non-recursive case you realize that there's actually nothing special whatsoever about how TCO is applied to recursive functions.

Source: How Tail Call Optimization Works, an article by Evan Klitzke.