4 ms·
The difficulty depends on the language and on what you're trying to do. In Python the correct translation is usually to replace return with yield and work with
by btilly 14y ago
The difficulty depends on the language and on what you're trying to do.
In Python the correct translation is usually to replace return with yield and work with iterators. In a language without that feature, well, http://perl.plover.com/Stream/stream.html http://perl.plover.com/Stream/stream.html demonstrates what a solution looks like in Perl. A Java solution to the same issue is going to be..verbose.
- hythloday 14y agoI avoided generators because implementing ersatz laziness with lazy language features seemed like cheating - you can read my Python lists as C arrays, but it's much harder to map that onto coroutines without significant handwaving.