Ask a Question related to Ruby, Design and Development.
-
Simon Strandgaard #1
[ann] iterator 0.1
homepage:
[url]http://raa.ruby-lang.org/list.rhtml?name=iterator[/url]
download:
[url]http://rubyforge.org/download.php/213/iterator-0.1.tar.gz[/url]
About
=====
If Ryby's native iterators (yield+each) ain't flexible enough,
you may want to try using this collection of bidirectional
iterator classes. Building custom iterator classes are simple.
This is a simple implementation of GoF iterator-pattern.
Status
======
The overall design are stable. I don't expect any big changes.
Collection, iterates over an Array or similar containers.
Reverse, decorator which reverses the iterator.
Range, iterate in the range between two iterators.
Concat, concat multiple iterators into one.
Continuation, turn #each_word/#each_byte into an iterator.
License
=======
Ruby's license.
Example
=======
We can virtually concatene two arrays, so that they appear
as they were a single array.
def test_concat_sort
i1 = [5, 3, 1].create_iterator
i2 = [2, 4, 6].create_iterator
iterator = Iterator::Concat.new(i1, i2)
assert_equal((1..6).to_a, iterator.sort)
end
The iterator base class looks like this.
Please comment on this interface. Is it OK?
Does it need anything?
class Iterator
# close iterator after usage.
def close
# set position at first element
def first
# goto next element
def next
# true if we have reached the end
def is_done?
# set position at last element
def last
# goto previous element
def prev
# get the value of current element
def current
# set the value of current element
def current=(value)
# iterate over all elements (forward)
def each
# iterate over all elements (backward)
def reverse_each
# create a reverse iterator
def reverse
# typical enum methods also
include Enumerable
end
Authors last words
==================
We are curios to hear what your first-impression are, What do
you want from 'iterator.rb'? What are your requirements?
Please contribute with extensions or suggestions. In case you
observe bugs or other misbehavier, then please drop us a mail.
Messages must be submitted via this web-forum (prefered way of contact):
[url]http://rubyforge.org/forum/forum.php?forum_id=46[/url]
--
Simon Strandgaard
Simon Strandgaard Guest
-
What's the iterator when using CFGRID?
new to CF7, and was wondering how would i output/alert the PK (primary key) when looping through the results using CFGRID? easily done when output'n... -
ANNOUNCE: Iterator v0.02 and associated modules.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Version 0.02 of the following modules Iterator Iterator::Util Iterator::IO Iterator::DBI... -
How To Write the external Iterator?
Easy... 1. Learn how to set the clock correctly on your computer. 2. Learn basic etiquette in usenet (i.e. not cross posting to a ton of... -
Any way to advance to an iterator prematurely?
All- In the code below, is there an way to put a condition just before <do a big bunch of stuff?> that will cause the iterator to advance to the... -
How to I Iterator through a CheckBoxList?
This is an ASP.NET using C# website -
Nikolai Weibull #2
Re: [ann] iterator 0.1
* Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:
my first impression is that you must really, really love iterators ;-)> We are curios to hear what your first-impression are, What do
> you want from 'iterator.rb'? What are your requirements?
anyway, may be interesting to see how useful this is. this may be
something to integrate into (or other way around perhaps? ;-) RDSL
[url]http://rubyforge.org/projects/rdsl/[/url]
nikolai
--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: [url]www.pcppopper.org[/url] :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
Nikolai Weibull Guest
-
ts #3
Re: [ann] iterator 0.1
>>>>> "N" == Nikolai Weibull <ruby-talk@pcppopper.org> writes:
N> * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:N> my first impression is that you must really, really love iterators ;-)>> We are curios to hear what your first-impression are, What do
>> you want from 'iterator.rb'? What are your requirements?
N> anyway, may be interesting to see how useful this is. this may be
N> something to integrate into (or other way around perhaps? ;-) RDSL
Well, the problem is that it exist something similar in 1.8.1
# == Overview
#
# This library provides the Generator class, which converts an
# internal iterator (i.e. an Enumerable object) to an external
# iterator. In that form, you can roll many iterators independently.
svg% grep 'def ' generator.rb
def initialize(enum = nil, &block)
def yield(value)
def end?()
def next?()
def index()
def pos()
def next()
def current()
def rewind()
def each
def initialize(*enums)
def size
def length
def end?(i = nil)
def each
def test_block1
def test_block2
def test_each
def test_each
svg%
Guy Decoux
ts Guest
-
Mark Wilson #4
Re: [ann] iterator 0.1
On Nov 20, 2003, at 1:11 PM, ts wrote:
A certain level of convergence is, in my opinion, a good sign.>>>>>>> "N" == Nikolai Weibull <ruby-talk@pcppopper.org> writes:
> N> * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:> N> my first impression is that you must really, really love iterators>>> We are curios to hear what your first-impression are, What do
>>> you want from 'iterator.rb'? What are your requirements?
> ;-)
> N> anyway, may be interesting to see how useful this is. this may be
> N> something to integrate into (or other way around perhaps? ;-) RDSL
>
> Well, the problem is that it exist something similar in 1.8.1
>
> [snip]
Regards,
Mark
Mark Wilson Guest
-
Simon Strandgaard #5
Re: [ann] iterator 0.1
On Fri, 21 Nov 2003 03:11:28 +0900, ts wrote:
You are welcome to use 'iterator.rb' in RDSL.. However 'iterator.rb' are>>>>>>> "N" == Nikolai Weibull <ruby-talk@pcppopper.org> writes:
> N> * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:> N> my first impression is that you must really, really love iterators ;-)>>> We are curios to hear what your first-impression are, What do
>>> you want from 'iterator.rb'? What are your requirements?
> N> anyway, may be interesting to see how useful this is. this may be
> N> something to integrate into (or other way around perhaps? ;-) RDSL
under Ruby license and RDSL are under LGPL. I think you can make a
vendor-branch, and import 'iterator.rb' into your cvs-repository:
[url]http://www.loria.fr/~molli/cvs/doc/cvs_13.html#SEC98[/url]
I wasn't aware of 'generator.rb'. The 'Generator from a block' idea> Well, the problem is that it exist something similar in 1.8.1
>
> # == Overview
> #
> # This library provides the Generator class, which converts an
> # internal iterator (i.e. an Enumerable object) to an external
> # iterator. In that form, you can roll many iterators independently.
is good, I will rip it.
I started working on the iterator before Ruby-1.8.1 were released,
because I needed it for my regexp-engine in order to iterate over many
different kinds of input-streams. Also because I needed a robust-iterator.
'generator.rb' cannot replace 'iterator.rb'.
I originally tried out Horst Duchene's 'stream' package, but found it too
counter-intuitive. I don't believe there are other iterator packages ?
--
Simon Strandgaard
Simon Strandgaard Guest
-
Simon Strandgaard #6
Re: [ann] iterator 0.1
On Fri, 21 Nov 2003 03:04:48 +0900, Nikolai Weibull wrote:
true> * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:> my first impression is that you must really, really love iterators ;-)>> We are curios to hear what your first-impression are, What do
>> you want from 'iterator.rb'? What are your requirements?
[snip]> anyway, may be interesting to see how useful this is.
The most interesting thing which I can think of right now,
where only iterators will do, are for my Robust-Array/iterator.
A Robust-iterator is a iterator which keeps pointing at the
same element, even though you insert/delete elements in the
same data structure. When insert/delete occur, all iterators
gets notified about the delta-change. AEditor needs it.
See implementation of robust-Array/iterator here:
[url]http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/projects/experimental/iterator2/robust.rb?rev=1.2&cvsroot=aeditor&content-type=text/vnd.viewcvs-markup[/url]
See unittest of robust-Array/iterator here:
[url]http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/projects/experimental/iterator2/test_robust.rb?rev=1.2&cvsroot=aeditor&content-type=text/vnd.viewcvs-markup[/url]
--
Simon Strandgaard
Simon Strandgaard Guest
-
Robert Klemme #7
Re: [ann] iterator 0.1
"ts" <decoux@moulon.inra.fr> schrieb im Newsbeitrag
news:200311201811.hAKIBOa26104@moulon.inra.fr...;-)>> >>>>> "N" == Nikolai Weibull <ruby-talk@pcppopper.org> writes:
> N> * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:> N> my first impression is that you must really, really love iterators> >> We are curios to hear what your first-impression are, What do
> >> you want from 'iterator.rb'? What are your requirements?Seems like I have to upgrade:> N> anyway, may be interesting to see how useful this is. this may be
> N> something to integrate into (or other way around perhaps? ;-) RDSL
>
> Well, the problem is that it exist something similar in 1.8.1
09:23:31 [w]: irb -r generator
/usr/lib/ruby/1.8/irb/init.rb:215:in `require':
/cygdrive/w/lib/ruby/generator.rb:33: unterminated string meets end of
file (SyntaxError)
/cygdrive/w/lib/ruby/generator.rb:33: syntax error from
/usr/lib/ruby/1.8/irb/init.rb:215:in `load_modules'
from /usr/lib/ruby/1.8/irb/init.rb:213:in `each'
from /usr/lib/ruby/1.8/irb/init.rb:213:in `load_modules'
from /usr/lib/ruby/1.8/irb/init.rb:21:in `setup'
from /usr/lib/ruby/1.8/irb.rb:54:in `start'
from /usr/bin/irb:13
09:23:36 [w]: ruby -v
ruby 1.8.0 (2003-08-04) [i386-cygwin]
09:23:38 [w]: uname -a
CYGWIN_NT-5.0 bond 1.5.5(0.94/3/2) 2003-09-20 16:31 i686 unknown unknown
Cygwin
09:23:42 [w]:
robert
Robert Klemme Guest
-
ts #8
Re: [ann] iterator 0.1
>>>>> "R" == Robert Klemme <bob.news@gmx.net> writes:
R> Seems like I have to upgrade:
R> 09:23:31 [w]: irb -r generator
yes,
nasun% ruby -v
ruby 1.8.1 (2003-10-31) [sparc-solaris2.8]
nasun%
nasun% irb -r generator
irb(main):001:0> g = Generator.new(['A', 'B', 'C', 'Z'])
=> #<Generator:0x1002f9830 @cont_next=nil, @queue=["A"], @cont_endp=nil, @index=0, @block=#<Proc:0x0000000100329b20@/opt/sparcv9/lib/ruby/1.8/generator.rb:69>, @cont_yield=#<Continuation:0x1002f94e8>>
irb(main):002:0> puts g.next while g.next?
A
B
C
Z
=> nil
irb(main):003:0> nasun%
Guy Decoux
ts Guest
-
gabriele renzi #9
Re: [ann] iterator 0.1
il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
scritto::
where did 'svg%' go ? ;)>nasun% ruby -v
gabriele renzi Guest
-
Simon Strandgaard #10
Re: [ann] iterator 0.1
On Fri, 21 Nov 2003 20:27:40 +0000, gabriele renzi wrote:
also, what happened to 'pigeon>' ?> il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
> scritto::
>
>>>>nasun% ruby -v
> where did 'svg%' go ? ;)
--
Simon Strandgaard
Simon Strandgaard Guest
-
ts #11
[OT] Re: [ann] iterator 0.1
>>>>> "S" == Simon Strandgaard <neoneye@adslhome.dk> writes:
S> On Fri, 21 Nov 2003 20:27:40 +0000, gabriele renzi wrote:S> also, what happened to 'pigeon>' ?>> il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
>> scritto::
>>
>>>>>>> nasun% ruby -v
>> where did 'svg%' go ? ;)
You have forgotten condor% [ruby-talk:25826], aestivum% [ruby-talk:47494]
Guy Decoux
ts Guest
-
gabriele renzi #12
Re: [OT] Re: [ann] iterator 0.1
il Sun, 23 Nov 2003 02:12:46 +0900, ts <decoux@moulon.inra.fr> ha
scritto::
mh.. I didn't even knew ruby at that time I suppose :)>
> You have forgotten condor% [ruby-talk:25826], aestivum% [ruby-talk:47494]
gabriele renzi Guest
-
Martin DeMello #13
Re: [ann] iterator 0.1
Simon Strandgaard <neoneye@adslhome.dk> wrote:
poisoned in the park?> On Fri, 21 Nov 2003 20:27:40 +0000, gabriele renzi wrote:
>>>> il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
>> scritto::
>>
>>>>>>>nasun% ruby -v
>> where did 'svg%' go ? ;)
> also, what happened to 'pigeon>' ?
martin
Martin DeMello Guest
-
Robert Klemme #14
[OT] Re: [ann] iterator 0.1
"Martin DeMello" <martindemello@yahoo.com> schrieb im Newsbeitrag
news:vubwb.137096$jy.117581@clgrps13...You mean, Georg Kreisler was there?> Simon Strandgaard <neoneye@adslhome.dk> wrote:>> > On Fri, 21 Nov 2003 20:27:40 +0000, gabriele renzi wrote:
> >> >> >> il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
> >> scritto::
> >>
> >>
> >>>nasun% ruby -v
> >>
> >> where did 'svg%' go ? ;)
> > also, what happened to 'pigeon>' ?
> poisoned in the park?
[url]http://www.metrolyrics.com/lyrics/121810/Georg_Kreisler/Tauberl_Vergiften/[/url]
[url]http://www.br-online.de/alpha/forum/vor0311/20031123_i.shtml[/url]
Note: you should be German speaking to enjoy this song text...
;-)
robert
Robert Klemme Guest
-
Hal Fulton #15
Re: [OT] Re: [ann] iterator 0.1
Robert Klemme wrote:
Fascinating... this appears to be a translation of the original> "Martin DeMello" <martindemello@yahoo.com> schrieb im Newsbeitrag
> news:vubwb.137096$jy.117581@clgrps13...
>>>>Simon Strandgaard <neoneye@adslhome.dk> wrote:
>>>>>>>On Fri, 21 Nov 2003 20:27:40 +0000, gabriele renzi wrote:
>>>
>>>
>>>>il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
>>>>scritto::
>>>>
>>>>
>>>>
>>>>>nasun% ruby -v
>>>>
>>>>where did 'svg%' go ? ;)
>>>
>>>also, what happened to 'pigeon>' ?
>>poisoned in the park?
>
> You mean, Georg Kreisler was there?
>
> [url]http://www.metrolyrics.com/lyrics/121810/Georg_Kreisler/Tauberl_Vergiften/[/url]
> [url]http://www.br-online.de/alpha/forum/vor0311/20031123_i.shtml[/url]
>
> Note: you should be German speaking to enjoy this song text...
>
> ;-)
song (in English) by Tom Lehrer.
I guess people everywhere are pretty much the same... ;)
Hal
Hal Fulton Guest
-
Robert Klemme #16
Re: [OT] Re: [ann] iterator 0.1
"Hal Fulton" <hal9000@hypermetrics.com> schrieb im Newsbeitrag
news:3FC1B89D.5080908@hypermetrics.com...[url]http://www.metrolyrics.com/lyrics/121810/Georg_Kreisler/Tauberl_Vergiften/[/url]> Robert Klemme wrote:> > "Martin DeMello" <martindemello@yahoo.com> schrieb im Newsbeitrag
> > news:vubwb.137096$jy.117581@clgrps13...
> >> >> >>Simon Strandgaard <neoneye@adslhome.dk> wrote:
> >>
> >>>On Fri, 21 Nov 2003 20:27:40 +0000, gabriele renzi wrote:
> >>>
> >>>
> >>>>il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
> >>>>scritto::
> >>>>
> >>>>
> >>>>
> >>>>>nasun% ruby -v
> >>>>
> >>>>where did 'svg%' go ? ;)
> >>>
> >>>also, what happened to 'pigeon>' ?
> >>
> >>poisoned in the park?
> >
> > You mean, Georg Kreisler was there?
> >
> >How old is that one?>> > [url]http://www.br-online.de/alpha/forum/vor0311/20031123_i.shtml[/url]
> >
> > Note: you should be German speaking to enjoy this song text...
> >
> > ;-)
> Fascinating... this appears to be a translation of the original
> song (in English) by Tom Lehrer.
Pigeons, too. :-)> I guess people everywhere are pretty much the same... ;)
robert
Robert Klemme Guest
-
Daniel Kelley #17
Re: [OT] Re: [ann] iterator 0.1
>>>>> "Robert" == Robert Klemme <bob.news@gmx.net> writes:
Robert> "Hal Fulton" <hal9000@hypermetrics.com> schrieb im
Robert> Newsbeitrag news:3FC1B89D.5080908@hypermetrics.com...Robert> [url]http://www.metrolyrics.com/lyrics/121810/Georg_Kreisler/Tauberl_Vergiften/[/url]>> Robert Klemme wrote: > "Martin DeMello"
>> <martindemello@yahoo.com> schrieb im Newsbeitrag >
>> news:vubwb.137096$jy.117581@clgrps13...>> <decoux@moulon.inra.fr> ha >>>>scritto::>> >
>> >>Simon Strandgaard <neoneye@adslhome.dk> wrote:
>> >>
>> >>>On Fri, 21 Nov 2003 20:27:40 +0000, gabriele renzi wrote:
>> >>>
>> >>>
>> >>>>il Fri, 21 Nov 2003 19:33:27 +0900, ts>> >>>>
>> >>>>
>> >>>>
>> >>>>>nasun% ruby -v
>> >>>>
>> >>>>where did 'svg%' go ? ;)
>> >>>
>> >>>also, what happened to 'pigeon>' ?
>> >>
>> >>poisoned in the park?
>> >
>> >
>> > You mean, Georg Kreisler was there?
>> >
>> >Robert> How old is that one?>> text...>> > [url]http://www.br-online.de/alpha/forum/vor0311/20031123_i.shtml[/url]
>> >
>> > Note: you should be German speaking to enjoy this song>>>> >
>> > ;-)
>> Fascinating... this appears to be a translation of the original
>> song (in English) by Tom Lehrer.
Released in 1959 on the album "More of Tom Lehrer".
d.k.
Daniel Kelley Guest



Reply With Quote

