On Sat, 29 Oct 2005, Daniel Nugent wrote: > Hello, > > I've been considering the ways to add a particular language construct > (data flow variables) to Ruby. I've come up with, and implemented, > one method of doing this, but it relies on global variables (I > mentioned this on the list a month ago or so), so it's not something I > really want to stick with. > > Another way I've imagined doing it would involve changing the way > assignment works for instances of a Class while behaving more nicely. > > I'm envisioning something like this: > > foo = DataFlow.new > > bar = Thread.new(foo) {|fooinarr| print fooinarr[0]} > baz = Thread.new(foo) {|fooinarr| sleep(3);fooinarr[0] = "Hello World, sorry I'm late"} you'll have to come up with something more challenging that that ;-) : harp:~ > cat a.rb require 'thread' class DataFlow def slots @slots ||= Hash::new{|h,k| h[k] = Queue::new} end def [] idx slots[ idx ].pop end def []= idx, val slots[ idx ].push val end end foo = DataFlow::new bar = Thread::new(foo){|fooinarr| puts fooinarr[0]} baz = Thread::new(foo){|fooinarr| sleep(3) and fooinarr[0] = "Hello World, sorry I'm late"} bar.join baz.join harp:~ > ruby a.rb Hello World, sorry I'm late i'm unclear as you __exactly__ what you can't do that you want to. maybe you don't need to change anything to get what you want. can you elaborate? kind regards. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | anything that contradicts experience and logic should be abandoned. | -- h.h. the 14th dalai lama ===============================================================================