------art_8266_25595746.1143211378148
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 3/24/06, Ross Bamford <rossrt / roscopeco.co.uk> wrote:
>
> Just a small fix:
>
> On Fri, 2006-03-24 at 22:49 +0900, Ross Bamford wrote:
> >   def initialize(enum)
> >     @yield = lambda do
> >       enum.each do |item|
> > -       @yield = callcc { |cc|
>   +       callcc { |cc|
> >           @next.call cc, item
> >         }
> >       end
> >       raise "Exhausted"
> >     end
> >   end
>
> Doesn't really hurt (as currently written) but it's unnecessary and
> could cause confusion.
>
> --
> Ross Bamford - rosco / roscopeco.REMOVE.co.uk


Well I got it!
Was I missing something or is my solution really better?

---------------------------------- 8< --------------------------
class Iterator
    class Exhausted < Exception; end
    def initialize( enum )
        @enum = enum
        @next = nil
    end

    def next
        return @next.call if @next
        @enum.each do
            |item|
            callcc{ |cc|
                @next = cc
                return item
            }
        end # do
        raise Exhausted, "No more items :("
    end # def next
end # class Iterator

i = Iterator.new( %w{ Ringo John Paul George } )
loop do; puts i.next; end





--
Deux choses sont infinies : l'univers et la bóŐise humaine ; en ce qui
concerne l'univers, je n'en ai pas acquis la certitude absolue.

- Albert Einstein

------art_8266_25595746.1143211378148--