lazy-seq – a historic view and why it is misunderstood
summary
A concise history and practical stance: lazy cons lets code build infinite structures like numbers infinite sequence by deferring tails, but causes stack overflows when many sequence wrappers pile up and leaks when code holds the head; operations like drop/filter reveal that lazy cons cannot defer knowing emptiness, so Clojure introduces lazy-cons vs lazy-seq (the latter delays creating a real seq and adds rest/seq semantics) — key rule: always call seq on a lazy-seq before testing emptiness. Reducers and chunked sequences (array-based chunks) try to mitigate overhead but do not replace lazy-seq.
AI-written summary · about
chapters (30)
- 0:00Introduction
- 1:14Origins of sequences
- 3:01Why lazy cons was added
- 4:06Infinite sequences with lazy cons
- 5:34Dynamic context pitfalls
- 6:18Stack overflows with sequences
- 7:22Memory efficiency
- 8:23Memory leaks from heads
- 9:05What defines a sequence
- 10:09Sequences as views
- 11:34Seekable collections
- 12:39Implicit seek on strings
- 13:20Generating sequences
- 14:47Side effects in sequences
- 15:30Cycle and concat
- 16:16Filtering sequences
- 16:58Historic cut in sequences
- 18:29lazy-seq macro
- 19:10Changes to sequence interface
- 20:32Full laziness
- 21:36Loss of nil punning
- 21:58Is lazy-seq still a sequence
- 22:40Sequences vs seekables
- 23:26Nil safety
- 23:50Polymorphism in sequences
- 25:13Improving sequence functions
- 26:17Reducers vs sequences
- 27:40Advantages of reducers
- 28:42Future of lazy-seq
- 29:03Q&A
related talks
59mLet's Get Lazy
36mWorking Hard to Keep Things Lazy
58mLet’s Get Lazy—The Real Power of Functional Programming
49mLazy Java
06mHow to Write a Fast, Reducible Collection
40mFun with Functional Programming in Clojure
52mAn Intuition for List Folds
01h 03mUnleash Your Data with Clojure: Using Transducers and Sequences
