E
Eric Torreborre
There is a complete lazy list implementation from Reginald Braithwaite webs=
ite:=0A=0Ahttp://raganwald.com/source/lazy_lists.html=0A=0AIt supports a lo=
t of operations on this kind of "infinite" structures such as merge and car=
tesian product.=0A=0AThat one could make it to the core!=0A=0AEric.=0A =0A-=
--------------------------------------------------------------------------=
=0AEric TORREBORRE=0Atel: +81 (0)90 5580 3280=0Ae-mail: (e-mail address removed)=
om / (e-mail address removed)=0Ablog: http://etorreborre.blogspot.com=0A---=
------------------------------------------------------------------------=0A=
=0A----- Message d'origine ----=0ADe : Robert Dober <[email protected]=
elieve that the core is the place to put such=0Athings, furthermore I belie=
ve it is too specific a feature, a more=0Ageneral approach might have bette=
r chances to be fit for the core; Yet=0AI do not think what follows is fit =
for the core either, but maybe you=0Afind it interesting or helpful:=0A=0Ac=
lass Lazy=0A def initialize init, op, *args=0A @init =3D init=0A @op=
=3D op=0A @args =3D args.dup=0A end=0A=0A def upto value=0A retu=
rn [] if value < 1=0A (2..value).inject([@init]){ |acc,| acc << acc.last=
send( @op, *@args ) }=0A end=0Aend # class Lazy=0A=0A505/6 > irb -r lazy.=
rb=0Airb(main):001:0> l =3D Lazy.new 1, :+, 2=0A=3D> #<Lazy:0xb7ddfa60 @arg=
s=3D[2], @init=3D1, @op=3D:+>=0Airb(main):002:0> l.upto 5=0A=3D> [1, 3, 5, =
7, 9]=0Airb(main):003:0> m =3D Lazy.new 2, :*, 3=0A=3D> #<Lazy:0xb7dd4908 @=
args=3D[3], @init=3D2, @op=3D:*>=0Airb(main):004:0> m.upto 4=0A=3D> [2, 6, =
18, 54]=0Airb(main):005:0>=0A=0ACheers=0ARobert=0A=0AP.S. Implementations w=
ithout #inject are theoretically possible =0AR.=0A-- =0AYou see things; a=
nd you say Why?=0ABut I dream things that never were; and I say Why not?=0A=
-- George Bernard Shaw=0A=0A=0A=0A=0A=0A=0A=0A=0A =0A=09=0A=09=09=0A__=
_________________________________________________________________________ =
=0AD=E9couvrez une nouvelle fa=E7on d'obtenir des r=E9ponses =E0 toutes vos=
questions ! =0AProfitez des connaissances, des opinions et des exp=E9rienc=
es des internautes sur Yahoo! Questions/R=E9ponses =0Ahttp://fr.answers.yah=
oo.com
ite:=0A=0Ahttp://raganwald.com/source/lazy_lists.html=0A=0AIt supports a lo=
t of operations on this kind of "infinite" structures such as merge and car=
tesian product.=0A=0AThat one could make it to the core!=0A=0AEric.=0A =0A-=
--------------------------------------------------------------------------=
=0AEric TORREBORRE=0Atel: +81 (0)90 5580 3280=0Ae-mail: (e-mail address removed)=
om / (e-mail address removed)=0Ablog: http://etorreborre.blogspot.com=0A---=
------------------------------------------------------------------------=0A=
=0A----- Message d'origine ----=0ADe : Robert Dober <[email protected]=
uin 2007, 20h29mn 46s=0AObjet : Re: What about a 'series' type?=0A=0AOn 6/7==0A=C0 : ruby-talk ML <[email protected]>=0AEnvoy=E9 le : Jeudi, 7 J=
elieve that the core is the place to put such=0Athings, furthermore I belie=
ve it is too specific a feature, a more=0Ageneral approach might have bette=
r chances to be fit for the core; Yet=0AI do not think what follows is fit =
for the core either, but maybe you=0Afind it interesting or helpful:=0A=0Ac=
lass Lazy=0A def initialize init, op, *args=0A @init =3D init=0A @op=
=3D op=0A @args =3D args.dup=0A end=0A=0A def upto value=0A retu=
rn [] if value < 1=0A (2..value).inject([@init]){ |acc,| acc << acc.last=
send( @op, *@args ) }=0A end=0Aend # class Lazy=0A=0A505/6 > irb -r lazy.=
rb=0Airb(main):001:0> l =3D Lazy.new 1, :+, 2=0A=3D> #<Lazy:0xb7ddfa60 @arg=
s=3D[2], @init=3D1, @op=3D:+>=0Airb(main):002:0> l.upto 5=0A=3D> [1, 3, 5, =
7, 9]=0Airb(main):003:0> m =3D Lazy.new 2, :*, 3=0A=3D> #<Lazy:0xb7dd4908 @=
args=3D[3], @init=3D2, @op=3D:*>=0Airb(main):004:0> m.upto 4=0A=3D> [2, 6, =
18, 54]=0Airb(main):005:0>=0A=0ACheers=0ARobert=0A=0AP.S. Implementations w=
ithout #inject are theoretically possible =0AR.=0A-- =0AYou see things; a=
nd you say Why?=0ABut I dream things that never were; and I say Why not?=0A=
-- George Bernard Shaw=0A=0A=0A=0A=0A=0A=0A=0A=0A =0A=09=0A=09=09=0A__=
_________________________________________________________________________ =
=0AD=E9couvrez une nouvelle fa=E7on d'obtenir des r=E9ponses =E0 toutes vos=
questions ! =0AProfitez des connaissances, des opinions et des exp=E9rienc=
es des internautes sur Yahoo! Questions/R=E9ponses =0Ahttp://fr.answers.yah=
oo.com