Ask a Question related to Ruby, Design and Development.

  1. #1

    Default [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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. How to I Iterator through a CheckBoxList?
      This is an ASP.NET using C# website
  3. #2

    Default Re: [ann] iterator 0.1

    * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:
    > We are curios to hear what your first-impression are, What do
    > you want from 'iterator.rb'? What are your requirements?
    my first impression is that you must really, really love iterators ;-)
    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

  4. #3

    Default Re: [ann] iterator 0.1

    >>>>> "N" == Nikolai Weibull <ruby-talk@pcppopper.org> writes:

    N> * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:
    >> We are curios to hear what your first-impression are, What do
    >> you want from 'iterator.rb'? What are your requirements?
    N> my first impression is that you must really, really love iterators ;-)
    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

  5. #4

    Default Re: [ann] iterator 0.1


    On Nov 20, 2003, at 1:11 PM, ts wrote:
    >>>>>> "N" == Nikolai Weibull <ruby-talk@pcppopper.org> writes:
    >
    > N> * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:
    >>> We are curios to hear what your first-impression are, What do
    >>> you want from 'iterator.rb'? What are your requirements?
    > N> my first impression is that you must really, really love iterators
    > ;-)
    > 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]
    A certain level of convergence is, in my opinion, a good sign.

    Regards,

    Mark


    Mark Wilson Guest

  6. #5

    Default Re: [ann] iterator 0.1

    On Fri, 21 Nov 2003 03:11:28 +0900, ts wrote:
    >>>>>> "N" == Nikolai Weibull <ruby-talk@pcppopper.org> writes:
    >
    > N> * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:
    >>> We are curios to hear what your first-impression are, What do
    >>> you want from 'iterator.rb'? What are your requirements?
    > N> my first impression is that you must really, really love iterators ;-)
    > 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
    You are welcome to use 'iterator.rb' in RDSL.. However 'iterator.rb' are
    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]

    > 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.
    I wasn't aware of 'generator.rb'. The 'Generator from a block' idea
    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

  7. #6

    Default Re: [ann] iterator 0.1

    On Fri, 21 Nov 2003 03:04:48 +0900, Nikolai Weibull wrote:
    > * Simon Strandgaard <qj5nd7l02@sneakemail.com> [Nov, 20 2003 17:40]:
    >> We are curios to hear what your first-impression are, What do
    >> you want from 'iterator.rb'? What are your requirements?
    > my first impression is that you must really, really love iterators ;-)
    true

    > anyway, may be interesting to see how useful this is.
    [snip]

    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

  8. #7

    Default 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]:
    > >> We are curios to hear what your first-impression are, What do
    > >> you want from 'iterator.rb'? What are your requirements?
    > N> my first impression is that you must really, really love iterators
    ;-)
    > 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
    Seems like I have to upgrade:

    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

  9. #8

    Default 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

  10. #9

    Default Re: [ann] iterator 0.1

    il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
    scritto::

    >nasun% ruby -v
    where did 'svg%' go ? ;)
    gabriele renzi Guest

  11. #10

    Default Re: [ann] iterator 0.1

    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>' ?

    --
    Simon Strandgaard


    Simon Strandgaard Guest

  12. #11

    Default [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:
    >> il Fri, 21 Nov 2003 19:33:27 +0900, ts <decoux@moulon.inra.fr> ha
    >> scritto::
    >>
    >>
    >>> nasun% ruby -v
    >>
    >> where did 'svg%' go ? ;)
    S> also, what happened to 'pigeon>' ?

    You have forgotten condor% [ruby-talk:25826], aestivum% [ruby-talk:47494]



    Guy Decoux




    ts Guest

  13. #12

    Default Re: [OT] Re: [ann] iterator 0.1

    il Sun, 23 Nov 2003 02:12:46 +0900, ts <decoux@moulon.inra.fr> ha
    scritto::

    >
    > You have forgotten condor% [ruby-talk:25826], aestivum% [ruby-talk:47494]
    mh.. I didn't even knew ruby at that time I suppose :)
    gabriele renzi Guest

  14. #13

    Default Re: [ann] iterator 0.1

    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?

    martin
    Martin DeMello Guest

  15. #14

    Default [OT] Re: [ann] iterator 0.1


    "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...

    ;-)

    robert

    Robert Klemme Guest

  16. #15

    Default Re: [OT] Re: [ann] iterator 0.1

    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?
    >
    > [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...
    >
    > ;-)
    Fascinating... this appears to be a translation of the original
    song (in English) by Tom Lehrer.

    I guess people everywhere are pretty much the same... ;)

    Hal



    Hal Fulton Guest

  17. #16

    Default Re: [OT] Re: [ann] iterator 0.1


    "Hal Fulton" <hal9000@hypermetrics.com> schrieb im Newsbeitrag
    news:3FC1B89D.5080908@hypermetrics.com...
    > 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?
    > >
    > >
    [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...
    > >
    > > ;-)
    >
    > Fascinating... this appears to be a translation of the original
    > song (in English) by Tom Lehrer.
    How old is that one?
    > I guess people everywhere are pretty much the same... ;)
    Pigeons, too. :-)

    robert

    Robert Klemme Guest

  18. #17

    Default 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 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?
    >> >
    >> >
    Robert> [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...
    >> >
    >> > ;-)
    >>
    >> Fascinating... this appears to be a translation of the original
    >> song (in English) by Tom Lehrer.
    Robert> How old is that one?

    Released in 1959 on the album "More of Tom Lehrer".

    d.k.
    Daniel Kelley Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139