miyamuko #2167(2007/08/14 14:23 GMT) [ xtal ] Rating1/1=1.00
fiber でジェネレータにしました。 「(...)」 というのは可変長引数をあらわすオブジェクトです。でも、コレ使うのなんかクラッシュする。。。 あと、配列の分配がきれいにかけないです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
CrossProduct: class { - _list: []; initialize: method(...) { (...).each_ordered_arg { // ここのコメントを削除するとなぜかクラッシュする^^ if (it is String) { _list.push_back(it.split("").to_a); } else { _list.push_back(it); } } } all: method fiber { (fun (acc, rest) { if (rest.empty()) { yield acc; } else { x, xs: rest[0], rest.slice(1, rest.length); x { callee(acc ~ [it], xs); } } })([], _list); } } c: CrossProduct([0, 1], "ab", ["Foo", "Bar"]); c.all { it.p; }
Rating1/1=1.00-0+
[ reply ]
miyamuko
#2167()
[
xtal
]
Rating1/1=1.00
CrossProduct: class { - _list: []; initialize: method(...) { (...).each_ordered_arg { // ここのコメントを削除するとなぜかクラッシュする^^ if (it is String) { _list.push_back(it.split("").to_a); } else { _list.push_back(it); } } } all: method fiber { (fun (acc, rest) { if (rest.empty()) { yield acc; } else { x, xs: rest[0], rest.slice(1, rest.length); x { callee(acc ~ [it], xs); } } })([], _list); } } c: CrossProduct([0, 1], "ab", ["Foo", "Bar"]); c.all { it.p; }Rating1/1=1.00-0+
[ reply ]