generator method

Fiber とか coroutine とかいうヤツ。さっきと等価なもの。

i@u ~/test/boo> cat gen_method.boo
def gen():
    for x in range(5):
        yield x*x
for i in gen():
    print i
i@u ~/test/boo> booi gen_method.boo
0
1
4
9
16

高階?ジェネレータを書いてみる。 Enumerable を取ってジェネレータを返すと良い。

i@u ~/test/boo> cat gen_gen.boo
def gen(g):
    for x as int in g:
        yield x*x
for i in gen(gen(gen(range(5)))):
    print i
i@u ~/test/boo> booi gen_gen.boo
0
1
256
6561
65536
なにかあれば下記メールアドレスへ。
shinichiro.hamaji _at_ gmail.com
shinichiro.h