R
Roshan James
------_=_NextPart_001_01C5498D.C7C27962
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
How are iterators implemented in Ruby?=20
=20
Sometime back I had asked a questuin about invoking iterators in
locksteps and I was told that iterators in ruby are implemented as
closures that are passed to the called method. If iterators are passed
as closures then,
1) Every consumer of the iterator should undergo closure conversion
in some way
2) How is "break" implemented ?
This similar to how it would be done in Scheme or similar language that
inherently supports closures.=20
=20
=20
I was reading about CLU (the parent language for the iterator concept),
and they implemnted iterators on a single stack. I believe that that
would involve have caller and callee function frames to live on the
stack at the same time. The iteration would be implemnetd as goto
between these functions with a corresposding shift in stock location to
refernce locals. This implementation has the inherent limitation of not
being able to do multiple itetarors in lock step.=20
=20
Another alternative is that the itetror is converted to an object that
maintains state - a classical generator. This is what C# and Py do.=20
=20
How does Ruby do iterators ?
=20
Roshan
------_=_NextPart_001_01C5498D.C7C27962--
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
How are iterators implemented in Ruby?=20
=20
Sometime back I had asked a questuin about invoking iterators in
locksteps and I was told that iterators in ruby are implemented as
closures that are passed to the called method. If iterators are passed
as closures then,
1) Every consumer of the iterator should undergo closure conversion
in some way
2) How is "break" implemented ?
This similar to how it would be done in Scheme or similar language that
inherently supports closures.=20
=20
=20
I was reading about CLU (the parent language for the iterator concept),
and they implemnted iterators on a single stack. I believe that that
would involve have caller and callee function frames to live on the
stack at the same time. The iteration would be implemnetd as goto
between these functions with a corresposding shift in stock location to
refernce locals. This implementation has the inherent limitation of not
being able to do multiple itetarors in lock step.=20
=20
Another alternative is that the itetror is converted to an object that
maintains state - a classical generator. This is what C# and Py do.=20
=20
How does Ruby do iterators ?
=20
Roshan
------_=_NextPart_001_01C5498D.C7C27962--