From: Robert Dober Date: 2007-06-08T06:12:15+09:00 Subject: Re: What about a 'series' type? On 6/7/07, Robert Klemme wrote: > On 07.06.2007 21:41, Robert Dober wrote: > > On 6/7/07, Robert Klemme wrote: > > > > Robert I hope you do not mind my fantasy about/over/at??? your theme. > > Not at all. I had thought about the limit myself but did not want to > bother implementing it. Two remarks about your code: > > You include Enumerable but do not provide #each which is required. Sure, bad error; that was a leftover of your code, I do not really want to include it. > > You use instance variables for the iteration which is a bad thing > because this needless restricts usability (namely in the light of > multiple threads). I am not sure I understand this point, but we can get rid of that by expanding compute_next, but this will make the code much less readable :( The whole beast is not thread safe at all I guess, even without the instance var. It would be a nice challenge to make it thread safe, I guess we would need to cache values and synchronize the computation part, sounds *very* expansive, time and memory wise; probably not worth it . >Array and other's also do not store the iteration > state in instance variables but in local variables in method #each. Would that not be for performance reasons? > You > can try it with something like this which would not work if instance > variables would be used for storing iteration state > > a=(1..10).to_a > 2.times {|i| Thread.new(i) {|j| a.each {|x| puts "[#{j}-#{x}]"; sleep 0.5}}} I guess I do not know enough to understand this :( How is concurrent access to the method not a problem with local variables? However it would be sufficient to synchronize the access to the method only and not the access to the ivar. Is that what you are worried about? Cheers Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw