Writing and improving tail recursive functions
summary
Erlang uses tail recursion as the fundamental mechanism for long‑running processes: a function that ends in a tail call stays alive and avoids growing the call stack, so daemons, receive loops and TCP servers run forever without leaks. Examples use spawn, self, receive and gen_tcp to build an echo server that must be tail‑recursive to stay running, and an in‑house Kafka producer (buffering, reconnects, state machine) implemented with gen_fsm. Claims include handling ~100 billion events/month and aggressive internal benchmarks (40× then 200×, managers asked for 40,000×).
AI-written summary · about
chapters (11)
- 0:00Introduction
- 5:02Erlang history and goals
- 14:35Recursion and tail calls
- 20:39Amdahl's law and parallelism
- 21:00Tail recursion in processes
- 26:36Process isolation basics
- 30:13Long-running daemons
- 33:23Tail recursion with messages
- 35:51Network programming in Erlang
- 37:44State machines in distributed systems
- 41:36Tail recursion and processes
related talks
36mTaming the stack
57mMaximising Side Effects When Adopting Functional Programming
39mFunctional Concepts in Elixir
44m(Recursive) Functions Decoded
39mConcurrency Oriented Programming In A Modern World
37mY: Recursion The Hard Way
42mConcurrency Oriented Software
37mElixir - functional, concurrent, distributed programming
