From: William Morgan Date: 2004-08-27T05:42:05+09:00 Subject: Re: python generators to ruby closures, help Excerpts (reformatted) from zuzu's mail of 26 Aug 2004 (EDT): > http://www.ruby-doc.org/stdlib/libdoc/generator/rdoc/classes/Generator.html > > am i correct in assuming that "makes an internal iterator external" is > just another way of saying "turns a subroutine into a continuation", > "using yield rather than return"? or aka, a function to continuation > translator? I don't think that's right.T he goal of Generator is something much more specific: to turn an internal iterator, i.e. a method that takes a block argument, into an external iterator, i.e. an object with explicit #next? and #next methods. Think about trying to interlace two Enumerables, e.g. turn ["a","b","c"] and [1,2,3] into ["a",1,"b",2,"c",3]. You can't use Enumerable#each (an internal iterator) to do this in a natural way. Instead, you'd use Generator to create an object for each Enumerable and explicitly have a loop that called #next alternately on both objects. Ruby's internal iterators are far, far friendlier to use than, say, Java's external iterators (writing for loops really is a pain) but there are some problems they just don't yield (hah hah) natural solutions to. Sorry if that isn't what you were asking. I don't know whether this is related to Python's "generator" objects at all. -- William