[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re : What about a 'series' type?

Eric Torreborre

6/7/2007 3:04:00 PM

There is a complete lazy list implementation from Reginald Braithwaite website:http://raganwald.com/source/lazy_li... supports a lot of operations on this kind of "infinite" structures such as merge and cartesian product.That one could make it to the core!Eric. ---------------------------------------------------------------------------Eric TORREBORREtel: +81 (0)90 5580 3280e-mail: etorreborre@yahoo.com / etorreborre@docomo.ne.jpblog: http://etorreborre.blogspot.com----------------------------------------------------------------------... Message d'origine ----De : Robert Dober <robert.dober@gmail.com>À : ruby-talk ML <ruby-talk@ruby-lang.org>Envoyé le : Jeudi, 7 Juin 2007, 20h29mn 46sObjet : Re: What about a 'series' type?On 6/7/07, Peter Marsh <evil_grunger@hotmail.com> wrote:Honestly I do not believe that the core is the place to put suchthings, furthermore I believe it is too specific a feature, a moregeneral approach might have better chances to be fit for the core; YetI do not think what follows is fit for the core either, but maybe youfind it interesting or helpful:class Lazy def initialize init, op, *args @init = init @op = op @args = args.dup end def upto value return [] if value < 1 (2..value).inject([@init]){ |acc,| acc << acc.lastsend( @op, *@args ) } endend # class Lazy505/6 > irb -r lazy.rbirb(main):001:0> l = Lazy.new 1, :+, 2=> #<Lazy:0xb7ddfa60 @args=[2], @init=1, @op=:+>irb(main):002:0> l.upto 5=> [1, 3, 5, 7, 9]irb(main):003:0> m = Lazy.new 2, :*, 3=> #<Lazy:0xb7dd4908 @args=[3], @init=2, @op=:*>irb(main):004:0> m.upto 4=> [2, 6, 18, 54]irb(main):005:0>CheersRobertP.S. Implementations without #inject are theoretically possible ;)R.-- You see things; and you say Why?But I dream things that never were; and I say Why not?-- George Bernard Shaw ___________________________________________________________________________ Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses http://fr.answers...

1 Answer

Robert Dober

6/7/2007 3:19:00 PM

0

Pls no top post
On 6/7/07, Eric Torreborre <etorreborre@yahoo.com> wrote:
> There is a complete lazy list implementation from Reginald Braithwaite website:
>
> http://raganwald.com/source/lazy_...
>
> It supports a lot of operations on this kind of "infinite" structures such as merge and cartesian product.
>
> That one could make it to the core!
Not to core, given the dependencies it has, however I would be the
first to strongly advocate Facets to be put into the stdlib [No I am
not involved with Factes ;)]
Stdlib would be the target than for everything using Factes.

And maybe the following is of interest too:
http://blog.grayproductions.net/articles/2006/02/20/infini...

Please do not look too closely at my toy code it was to show that the
concept should be abstracted about and others have shown/done that
much better ;)

Cheers
Robert



--
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw