From: Simon Strandgaard Date: 2003-11-21T19:12:20+09:00 Subject: continuations and clone problem This class should convert internal-iterators to external-iterators. But how do I clone them? Any advice are deeply appreciated. -- Simon Strandgaard server> ruby a.rb a.rb:28:in `next': undefined method `call' for false:FalseClass (NoMethodError) from a.rb:28:in `callcc' from a.rb:28:in `next' from a.rb:43 server> expand -t2 a.rb class Object def deep_clone Marshal::load(Marshal.dump(self)) end end class IteratorContinuation def initialize(instance, symbol) @instance = instance @symbol = symbol first end def first @value = nil @resume_where = false @return_where = Proc.new{} @instance.method(@symbol).call {|i| @value = i callcc{|@resume_where| @return_where.call return } } @resume_where = false @return_where.call end def next callcc{|@return_where| @resume_where.call } end def is_done? @resume_where == false end def current @value end end i1 = IteratorContinuation.new("hello world", :each_byte) i1.next i1.next i1.next i2 = i1.clone # deep_clone not possible i2.next p i1.current p i2.current server>