Content deleted Content added
Line 443:
My suggestions:
* Point out that generators are really good for generating INFINITE sequences... just a little bit at a time, as the "consumer" needs the "next" item.
* Point out that most useful generators need to store a complicated state. (It is not just a simple unary test like "is this number even", which -- again -- can be accomplished
* Point out that languages that "support generators" do so by giving the programmer a simple way to do BOTH of those: generate "infinite sequences incrementally" and "save their state between calls".
* Pick a simple example that uses BOTH of those features. Such as: calculating the Fibonacci sequence. Let's see a Fib() generator in all the languages discussed.
* Point out that recursion and generation can each be used on certain calculations, but they are NOT synonymous.
* Compare and contrast a generator with a memoized recursive routine. (You can quickly calculate Fib(10000000) with a memoized recursive Fib, at the expense of the memory for the 1000000 prior entries. However, with a generator-based Fib(), constant memory (just two state variables) will serve to walk through all the values of Fib forever.)
If I have time someday, I may attempt to update the article with some of these suggestions.
|