Chapter 6 Functions, Defer, and Panic
Making functions “first-class citizens” means they can be assigned, passed, and returned like ordinary values, and can capture their environment to become closures. This capability, a luxury in Strachey’s day, is exactly what this chapter takes apart: how a function value is represented in memory, how a single call passes arguments and returns at the lowest level, how defer guarantees that “no matter which path we leave by, the cleanup still happens,” and how panic and recover unwind the call stack and then get caught. These features share one set of runtime machinery, and explaining it thoroughly lets us see the trade-offs Go makes among convenience, performance, and explicit control flow.