西尾泰和のブログ: RubyのyieldとPythonのyieldの違い

screenshot

RubyのyieldとPythonのyieldは実は全然違うような気がしてきたので、整理のために書いてみます。 まず、Rubyでeachに相当する物を自分で実装してみました。 # Ruby 1 class Array def my_each self.each{|x| yield x } end end [1, 2, 3, 4, 5].my_each{|x| puts x } これに相当する物をPythonで書くと、実はyieldを使いません。 # Python 1 class Array(list): def each(self, f): for i in self: f(i) def myprint(x): print x Array([1, 2, 3, 4, 5]).each( my...

http://www.nishiohirokazu.org/blog/2006/07/rubyyieldpythonyield.html
http://b.hatena.ne.jp/entry/http://www.nishiohirokazu.org/blog/2006/07/rubyyieldpythonyield.html