From: SonOfLilit Date: 2007-06-07T22:17:22+09:00 Subject: Re: What about a 'series' type? Actually, the syntax: a = Series.new(8) {|i| 5*i**3} a.collect{|i| i + 1}.select{|i| i % 2 == 0} # i.e. a is an enumerable object is quite cool and might be useful in some cases. The only problem I'm trying to solve is that of providing syntax for persistence (e.g. try to implement a series of Fibonacci numbers with the iterative algorithm using this Series syntax). Perhaps an optional hash argument that is used to give initial values to instance variables? With persistence, this could be a very useful idiom in many cases, and maybe even deserves to be stdlib. Aur On 6/7/07, Peter Seebach wrote: > In message , Peter Marsh writes: > >But this isn't any good if you want a arithmetic [3,5,7,9] or geometric > >[2,6,18,54] series. So I suggest this: > > > >arithmetic_series = Arith.new(First_Term,Common_Difference) > > > >aritmetic_series[9] will then generate the 10th term of the sequence (0 > >being the first to be consistent) and arithmetic_series[0..9] will > >return an array with the first to tenth terms. The same goes for a > >geometric series. > > > >gemometric_series = Geometric.new(First_Term,Common_Ratio) > > > >Now, there may be other ways to achieve this, but I think this way is > >nicer. > > These seem like special cases of Series.new([Start Terms], Proc). > > (Consider Fibbonacci sequences, for instance, or Pascal's Triangle.) > > -s > >