From: Masatoshi SEKI Date: 1999-04-17T02:56:17+09:00 Subject: [ruby-list:13827] Re: iterator <-> cursor (Re: iterator for Dummies) 咳です。 From: Shin-ichiro Hara > これの callcc 版を考えてみました。まず、Queue 相当のものなんですが、 > バッファがないのでかわいらしく Hole という名前にしました。 いまさら Thread 版を作ってみました。 以前に Thread 間 pipe が欲しくて作ったものに手を加えました。 Pipeクラスは原さんのHoleに相当します。 要素に nil を持てるように番兵 (PipeEOF) を導入しています。 また、複数の Thread が pipe に read/write できます。 ## イテレータとは関係ないっすね。最初はLinda みたいの作りたかったんです。 Pipe は次のように使います。 pipe = Pipe.new Thread.new do for i in 1..5 pipe.write(i) end pipe.close end while (v = pipe.read) != pipe.eof p v end 以下は、Pipe と 外部イテレータです。 -- pipe.rb -- #!/usr/local/bin/ruby require 'thread' class PipeEOF; end class PipeBrokenError