From: Peter Ertl Date: 2006-03-24T23:28:52+09:00 Subject: Re: iterator class not working aargh, again... remove that line, please: > raise "done" if @done > --- Urspr�ngliche Nachricht --- > Von: "Peter Ertl" > An: ruby-talk@ruby-lang.org (ruby-talk ML) > Betreff: Re: iterator class not working > Datum: Fri, 24 Mar 2006 23:25:59 +0900 > > Thanks for all you help. > > Finally, using two nested continuations works well... > > Here's my working code ... I am very curious about > optimization and alternatives from you guts. Afterall > I found this issue a very exciting one!! > > class Iterator > > def initialize(obj, method = :each) > @obj = obj > @method = method > end > > def next > raise "done" if @done > @iteration.call if @iteration > @iteration, @current = callcc do |loop| > @obj.send(@method) do |item| > callcc do |state| > loop.call state, item > end > end > nil > end > @current > end > > end > > names = %w{peter paul mary gordy john jane elwood} > > it = Iterator.new(names) > while item = it.next > puts item > end > > it = Iterator.new("Teststring", :each_byte) > while item = it.next > puts item.chr > end > > > peter > paul > mary > gordy > john > jane > elwood > T > e > s > t > s > t > r > i > n > g > > > > --- Urspr�ngliche Nachricht --- > > Von: Ross Bamford > > An: ruby-talk@ruby-lang.org (ruby-talk ML) > > Betreff: Re: iterator class not working > > Datum: Fri, 24 Mar 2006 23:10:05 +0900 > > > > 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 > > > > >