From: "Ara.T.Howard" Date: 2005-10-30T00:20:33+09:00 Subject: Re: What would it take to change the behaviour of variable assignment? On Sat, 29 Oct 2005, Daniel Nugent wrote: > It was a good shot. The thing is that DataFlow is not a collection. > It would be a wrapper around a single object assigned to it that > pauses the thread and forces it to pass when it has not been assigned > a value. all you need to do for that to work is is a method class Dataflow def queue @queue ||= Queue::new end def value queue.pop end def value= v queue.push v end end and then use bar = Thread::new(foo, "Monitor Thread"){|df, label| puts "#{ label } : #{ df.value }"} baz = Thread::new(foo, "Sleepy Thread") do |df, label| puts "#{ label } : Going to sleep." sleep 3 df.value = "Hello World, sorry I'm late" end although this approach, or the one your suggesting (though you cannot change rhs behvaiour in ruby) seems silly to me: i've written many data flow modules and it seems pretty useless to have a flow with only one input/output - which you are limited to with this method of setting the value via a single method or assignment. i would generally consider a 'flow' to be a directed acyclic graph of job dependacies - a tree - where some jobs can be run in parallel and some cannot. my flow library descibes this like # # a and b depend on nothing, c depends on a and b, d depends on c # flow = Flow::new a => nil, b => nil, c => [a, b], d => [c] here c is going to need the results of both a and b to begin. so here you need slots and then there is no problem. i realize you could make a, b, c, and d have the behaviour you are talking about - but thus far you've described putting it in the flow object itself... > The thing that makes the DFVs interesting is that the code you're running > wouldn't have to know it's being run in parallel to use the Dataflow > variables properly. It would just use them and be cool with it. > > It is a bit of an esoteric concern, I'll admit. But I wanna see if I can > make it work. sure. but this has nothing to with rhs behaviour... it seems like you're entire concern has nothing to do with global objects, flows, or threads and everything to do with if ruby can do this: x = SomeObject::new x = 42 and have x still be an instance of SomeObject - which is to say, in simple terms, that you want to override the assignment operator. to this is the answer is that you cannot, but you can easily come up with a syntax that looks very nice like x SomeObject::new x 42 or x = SomeObject::new x[42] so approaches exist for typing one or two fewer chars, but none of them involve typing ' = '. ;-) 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 ===============================================================================