From: zuzu Date: 2004-08-27T06:07:35+09:00 Subject: Re: python generators to ruby closures, help On Fri, 27 Aug 2004 05:42:05 +0900, William Morgan wrote: > 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 > > really my big question is how to use ruby for concurrent execution of unix-style pipes and filters chaining objects together as in the actors model (flow-based programming, aka dataflow). by definition of the actors model, this requires the use of continuations and bounded buffers (partial ordering) rather than threads; the idea being that you never have to manually manage (dead)locks much as a GC means never manually managing memory. (even the best programmers tend to suck at handcrafting memory management and thread locks; 99% of the time it's best left to the computer.) i've got data being generated all over the place. logfiles, web pages, file transfers, encryption/decryption of data, compression of data, etc. etc. some objects will generate data, with their outputs named by their methods. other objects will input data, filter it, and output the results, also named (as "ports) with methods. in the end some objects will consume that data, such as a framebuffer to display a gui or perhaps an IP:port on the internet to transfer files to. i would like ultimately to simply pipe these objects together and have them concurrently process their dataflow. this is basically what the actors model is all about. (it's also what unix streams / pipes & filters are all about.) hence my interest in generators and streams in ruby. does that present a clearer contextual picture? peace, -z