Hacker News new | ask | show | jobs
by ookdatnog 588 days ago
If you can read Lisp (Scheme) syntax, I think SICP [0] has the clearest demonstration of the utility of lazy streams. The problem it presents (calculating pi) is, admittedly, rather academic; but the concept of having values that evolve over "time" as first-class entities that you can abstract over is practically useful. I think that all of reactive programming (React, Angular, etc) is closely related to this idea (perhaps even originates from it), although the implementation and applications differ.

It's a long and effortful read, but the payoff is worth the effort.

[0] https://mitp-content-server.mit.edu/books/content/sectbyfn/b...

EDIT: I think the Perl article posted in a sibling comment uses essentially the same example (but for calculating e instead of pi), although I only skimmed it.

1 comments

I hadn't realized that SICP covered using lazy streams for calculating pi. That reminds me of this article I read recently about using lazy lists in Haskell to calculate pi by means of a few different algorithms.

https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/s...